// CPU scheduling simulation #include "sched.h" void fcfs::schedule(int nextproc, int timeindex, linked_list* run) { pcb* temp; if (nextproc) { temp = new pcb; temp->execution_time = nextproc; temp->time_remaining = nextproc; temp->start_time = timeindex; temp->exit_time = 0; // Just in case of wierdness run->insert_tail(temp); } run->seek_head(); // Just to be sure } // --------------------------------------------------------------------- void rr::schedule(int nextproc, int timeindex, linked_list* run) { pcb* temp; if (nextproc) { temp = new pcb; temp->execution_time = nextproc; temp->time_remaining = nextproc; temp->start_time = timeindex; temp->exit_time = 0; // Just in case of wierdness run->insert_tail(temp); } // rotate the run queue if (run->node_count() > 1) run->insert_tail(run->remove_head()); run->seek_head(); // Just to be sure } // --------------------------------------------------------------------- void sjn::schedule(int nextproc, int timeindex, linked_list* run) { pcb* temp; if (nextproc) { temp = new pcb; temp->execution_time = nextproc; temp->time_remaining = nextproc; temp->start_time = timeindex; temp->exit_time = 0; // Just in case of wierdness run->seek_head(); if (run->current() != NULL) run->next(); while ((run->current() != NULL) && (run->current()->execution_time <= temp->execution_time)) run->next(); if (run->current() == NULL) { run->insert_tail(temp); } else { run->insert_after(temp); } } run->seek_head(); // Just to be sure }