// Shahir Ahmed and Boosung Kim #include "../h/scheduler.h" extern pcb_t* readyQueue; // tail pointer to the queue of ready pcbs extern pcb_t* currentProcess; // pointer to the current executing process extern int processCount; // number of started but not terminated processes extern int softBlockCount; // number of soft blocked processes cpu_t startTime; #define TIMERVALUE(T) ((T) * (*((cpu_t *)TIMESCALEADDR))) void Scheduler() { currentProcess = removeProcQ(&readyQueue); if (currentProcess != NULL) { // current process exists STCK(startTime); //setTIMER(5000); setTIMER(TIMERVALUE(500000)); LDST(&(currentProcess->p_s)); } else { // ready queue is empty if (processCount == 0) { // halt and only respond to reset signal HALT(); } else if (softBlockCount > 0 && processCount > 0) { // idle waiting for device interrupt to occur setSTATUS(0xff01); // 0000 0 0000 0 000000 11111111 00 000001 WAIT(); } else if (softBlockCount == 0 && processCount > 0) { // deadlock PANIC(); } } }