void my_SLEEP(INT32 duration) { INT32 wakeTime = my_GET_TIME_OF_DAY() + duration; debug(GREY, "WakeTime: %d", wakeTime); MEMORY_MAPPED_IO mmio; mmio.Mode = Z502GetCurrentContext; MEM_READ(Z502Context, &mmio); PCB *newPCB; if ((newPCB = PCB_Get_By_ContextID(mmio.Field1)) == NULL) { debug(RED, "ERROR: Process Terminated in Sleep\n"); return; } TimerQueue_Lock("SLEEP"); debug(GREY, "new Timer Queue Item: PID %d wakeTime %d", newPCB->PID, wakeTime); TimerQueue_Add(newPCB, wakeTime); newPCB->status = PROCESS_Waiting; if (currentTimer > wakeTime || currentTimer == 0) { currentTimer = wakeTime; setTimer(duration); } else { debug(BLUE, "No need to set timer %d < %d", currentTimer, wakeTime); } TimerQueue_Unlock("SLEEP"); debug(YELLOW, "Time Before Idle %d\n", my_GET_TIME_OF_DAY()); TestMode("Before Dispatcher"); my_Dispatcher(); debug(YELLOW, "Time After Idle %d\n", my_GET_TIME_OF_DAY()); }
int main(void) { int i; TaskQueue taskQ1 = TaskQueue_Create(); TimerQueue uTimerQ = TimerQueue_Create(); TimerQueue mTimerQ = TimerQueue_Create(); TimerQueue_Add(&uTimerQ, 100, task1_Action1, 1); TimerQueue_Add(&uTimerQ, 200, task1_Action1, 2); TimerQueue_Add(&uTimerQ, 300, task1_Action1, 3); TimerQueue_Add(&uTimerQ, 250, task2_Action1, 4); TimerQueue_Add(&uTimerQ, 213, task2_Action1, 5); TimerQueue_Add(&uTimerQ, 13, task2_Action1, 6); TimerQueue_Add(&uTimerQ, 1000, task2_Action1, 7); Task* task_p = uTimerQ.HEAD; while(task_p != NULL) { printf(" - %d, (data=%d)\n", task_p->delay, task_p->data); task_p = task_p->next_p; } i=1001; while(i--) { TimerQueue_Tick(&uTimerQ, &taskQ1); } i=100; while(i--) TaskQueue_ExecuteNext(&taskQ1); /* TaskQueue_Add(&taskQ1, task1_Action1, 1); TaskQueue_Add(&taskQ1, task1_Action1, 2); TaskQueue_Add(&taskQ1, task1_Action1, 3); TaskQueue_Add(&taskQ1, task1_Action1, 4); TaskQueue_Add(&taskQ1, task2_Action1, 1); i=100; while(i--) TaskQueue_ExecuteNext(&taskQ1); TaskQueue_Add(&taskQ1, task1_Action1, 6); TaskQueue_Add(&taskQ1, task1_Action1, 7); TaskQueue_Add(&taskQ1, task2_Action1, 2); TaskQueue_Add(&taskQ1, task1_Action1, 9); TaskQueue_Add(&taskQ1, task1_Action1, 10); i=100; while(i--) TaskQueue_ExecuteNext(&taskQ1); */ return 0; }