Mercurial > hg > Game > CbCTaskManager
diff src/Scheduler.cbc @ 20:29835fc96f9f default tip
add Scheduler
add some documents.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 14 Jan 2010 15:08:06 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Scheduler.cbc Thu Jan 14 15:08:06 2010 +0900 @@ -0,0 +1,89 @@ +#include "Debug.h" +#include "Scheduler.h" + +typedef struct _Scheduler { + TaskQueue newTaskQ; + TaskQUeue finishTaskQ; + SchedTask taskp; /* previous task. */ + SchedTask taskc; /* current task. */ + SchedTask taskn; /* next task. */ + + __code (*read)(struct _Scheduler*); + __code (*exec)(struct _Scheduler*); + __code (*write)(struct _Scheduler*); +} Scheduler; + +__code +schedulerStart() +{ + sched->taskp = NoTask; + sched->taskc = NoTask; + goto getNewTask(); +} + +__code +loop(Scheduler *sched) +{ + sched->taskp = sched->taskc; + sched->taskc = sched->taskn; + sched->taskn = NULL; + if (/*have no task*/) { /* sched->taskp==NOP&&sched->taskp==NOP */ + // state patternできるか? + goto waitNewTask(sched); + } else { + goto getNewTask(sched); + } +} + +__code +getNewTask(Scheduler *sched) +{ + /* we should always have 3 tasks; previous, current and next. */ + sched->taskn = queuePoll(newTaskQ); + if (!sched->taskn) { + sched->taskn = NoTask; /* default task which do nothing. */ + } + goto sched->read(sched); +} + +__code +waitNewTask(Scheduler *sched) +{ + /* wait new task. */ + sched->taskn = queueTake(newTaskQ); + goto sched->read(sched); +} + + + +/* depending implementation. */ +__code +read(Scheduler *sched) +{ + /* start DMA for readbuffer of a next task. */ + /* wait for finishing DMA for readbuffer of a current task. */ + goto sched->exec(sched); +} +__code +execute(Scheduler *sched) +{ + /* execute current task. */ + goto sched->write(sched); +} +__code +write(Scheduler *sched) +{ + /* wait for finishing DMA for writebuffer of a previous task. */ + /* start DMA for writebuffer of a current task. */ + goto finishTask(sched); +} + +__code +finishTask(Scheduler *sched) +{ + queueOffer(sched->finishTaskQ, sched->taskp); + goto loop(sched); +} + + +