Mercurial > hg > CbC > CbC_xv6
changeset 374:bbca1e5fb946
add CbCProc
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Jul 2020 15:52:29 +0900 |
parents | 097a58a16a04 |
children | 4a4950e400b8 |
files | src/impl/CbCProcImpl.cbc src/impl/CbCProcImpl.h src/interface/CbCProc.h |
diffstat | 3 files changed, 122 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/impl/CbCProcImpl.cbc Tue Jul 07 15:52:29 2020 +0900 @@ -0,0 +1,111 @@ +#include "types.h" +#include "defs.h" +#include "param.h" +#include "memlayout.h" +#include "mmu.h" +#include "arm.h" +#include "proc.h" +#include "spinlock.h" + +#include "kernel.h" + +#interface "CbCProc.h" + +// ---- +// typedef struct CbCProcImpl <Type, Isa> impl CbCProc { +// __code next(....); +// } CbCProcImpl; +// ---- + +CbCProc* createCbCProcImpl(struct Context* cbc_context) { + struct CbCProc* cbc_proc = new CbCProc(); + struct CbCProcImpl* cb_c_proc_impl = new CbCProcImpl(); + cbc_proc->cbc_proc = (union Data*)cb_c_proc_impl; + cbc_proc->sched = C_schedCbCProcImpl; + cbc_proc->sleep = C_sleepCbCProcImpl; + cbc_proc->sleep1 = C_sleep1CbCProcImpl; + cbc_proc->wakeup = C_wakeupCbCProcImpl; + cbc_proc->wakeup1 = C_wakeup1CbCProcImpl; + return cbc_proc; +} + +__code schedCbCProcImpl(struct CbCProcImpl* cbc_proc, __code next(...)) { + int intena; + + if(!holding(&ptable.lock)) { + panic("sched ptable.lock"); + } + + if(cpu->ncli != 1) { + panic("sched locks"); + } + + if(proc->state == RUNNING) { + panic("sched running"); + } + + if(int_enabled ()) { + panic("sched interruptible"); + } + + intena = cpu->intena; + swtch(&proc->context, cpu->scheduler); + cpu->intena = intena; + + goto next(...); +} + +__code sleepCbCProcImpl(struct CbCProcImpl* cbc_proc, struct spinlock* lk, __code next(...)) { + //show_callstk("sleep"); + + if(proc == 0) { + panic("sleep"); + } + + if(lk == 0) { + panic("sleep without lk"); + } + + if(lk != &ptable.lock){ //DOC: sleeplock0 + acquire(&ptable.lock); //DOC: sleeplock1 + release(lk); + } + proc->chan = chan; + proc->state = SLEEPING; + proc->lk = lk; + + goto cbc_sched(cbc_sleep1, next); +} + +__code sleep1CbCProcImpl(struct CbCProcImpl* cbc_proc, __code next1(...)) { + struct spinlock *lk = proc->lk; + // Tidy up. + proc->chan = 0; + + // Reacquire original lock. + if(lk != &ptable.lock){ //DOC: sleeplock2 + release(&ptable.lock); + acquire(lk); + } + + goto next1(...); +} + +__code wakeupCbCProcImpl(struct CbCProcImpl* cbc_proc, void* chan, __code next1(...)) { + acquire(&ptable.lock); + goto wakeup1CbCProcImpl(chan); +} + +__code wakeup1CbCProcImpl(struct CbCProcImpl* cbc_proc, void* chan, __code next(...)) { + struct proc *p; + + for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { + if(p->state == SLEEPING && p->chan == chan) { + p->state = RUNNABLE; + } + } + + release(&ptable.lock); + goto next(...); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/impl/CbCProcImpl.h Tue Jul 07 15:52:29 2020 +0900 @@ -0,0 +1,3 @@ +typedef struct CbCProcImpl <Type, Isa> impl CbCProc { + __code next(....); +} CbCProcImpl;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/interface/CbCProc.h Tue Jul 07 15:52:29 2020 +0900 @@ -0,0 +1,8 @@ +typedef struct CbCProc <Type, Impl> { + __code sched(Impl* cbc_proc, __code next(...)); + __code sleep(Impl* cbc_proc, struct spinlock* lk, __code next(...)); + __code sleep1(Impl* cbc_proc, __code next1(...)); + __code wakeup(Impl* cbc_proc, void* chan, __code next1(...)); + __code wakeup1(Impl* cbc_proc, void* chan, __code next(...)); + __code next(....); +} CbCProc;