//------------------------------------------------------------------------ // Function to read the DEMO board switches //------------------------------------------------------------------------ nodebug void monitor_switches(void) { Switches_Active = FALSE; DemoBd_switch =0; costate { if (switchIn(S2)) //wait for switch S2 press abort; waitfor(DelayMs(50)); if (switchIn(S2)) //wait for switch release { Switches_Active = TRUE; DemoBd_switch = 1; abort; } } costate { if (switchIn(S3)) //wait for switch S3 press abort; waitfor(DelayMs(50)); if (switchIn(S3)) //wait for switch release { Switches_Active = TRUE; DemoBd_switch = 2; abort; } } }
void RunningProcs::makeRunnable(ProcessId *proc) { // The process must be in the InvalidState I(proc->getState()==InvalidState); // Now the process is runnable (but still not running) ProcessId *victimProc=proc->becomeReady(); // Get the CPU where the process would like to run CPU_t cpu=proc->getCPU(); // If there is a preferred CPU, try to schedule there if(cpu>=0){ // Get the GProcessor of the CPU GProcessor *core=getProcessor(cpu); // Are there available flows on this CPU if(core->availableFlows()){ // There is an available flow, grab it switchIn(cpu,proc); return; } } // Could not run the process on the cpu it wanted // If the process is not pinned to that processor, try to find another cpu if(!proc->isPinned()){ // Find an available processor GProcessor *core=getAvailableProcessor(); // If available processor found, run there if(core){ switchIn(core->getId(),proc); return; } } // Could not run on an available processor // If there is a process to evict, switch it out and switch the new one in its place if(victimProc){ I(victimProc->getState()==RunningState); // get the processor where victim process is running cpu=victimProc->getCPU(); switchOut(cpu, victimProc); switchIn(cpu,proc); victimProc->becomeNonReady(); makeRunnable(victimProc); } // No free processor, no process to evict // The new process has to wait its turn }
/* * Check the status of switch 2 */ cofunc void CheckSwitch2() { if (switchIn(S3)) // wait for switch press abort; // if button not down skip out waitfor(DelayMs(50)); // wait 50 ms if (switchIn(S3)) // wait for switch press abort; // if button not still down exit ledOut(DS4, ON); // led on SendMail(1); // send email since button was down 50 ms ledOut(DS4, OFF); // led off while (1) { waitfor(switchIn(S3)); // wait for button to go up waitfor(DelayMs(200)); // wait additional 200 ms if (switchIn(S3)) // wait for switch press break; // if button still up break out of while loop } }
void RunningProcs::makeNonRunnable(ProcessId *proc) { // It should still be running or ready I((proc->getState()==RunningState)||(proc->getState()==ReadyState)); // If it is still running, remove it from the processor if(proc->getState()==RunningState){ // Find the CPU where it is running CPU_t cpu=proc->getCPU(); // Remove it from there switchOut(cpu, proc); // Set the state to InvalidState to make the process non-runnable proc->becomeNonReady(); // Find another process to run on this cpu ProcessId *newProc=ProcessId::queueGet(cpu); // If a process has been found, switch it in if(newProc){ switchIn(cpu,newProc); } }else{ // Just set the state to InvalidState to make it non-runnable proc->becomeNonReady(); } }