Esempio n. 1
0
int manageContextSwitching( RunningState* run_state, Heap* ready_queue,
                            DeviceSet* device_set, ConfigData* configurations,
                            ActivityLog* activity_log )
{
    // case: we have a process that was running
    if( run_state->process_is_running )
    {
        // move the process to its next task and place the process in
        // the back of the ready queue
        increment_iterator( &(run_state->currently_running_process.job_list) );
        insert_heap( ready_queue, run_state->currently_running_process,
                     configurations->cpu_scheduler );
        run_state->process_is_running = false;
    }

    // get one from the queue if possible
    if( !is_Heap_empty( ready_queue ) )
    {
        // pop the item out of the queue
        run_state->currently_running_process =
            remove_PCB_from_Heap( ready_queue );
        run_state->process_is_running = true;
    }
    // case: there are no items to remove from the queue
        // leave the run state empty, with no process running

    // perform context switches until we get a processor destined
    // for the CPU or we are out of processeses to get
    while( ( get_listTask( &(run_state->currently_running_process.job_list) ).task_number != PROCESS ) &&
           !is_Heap_empty( ready_queue ) )
    {
        // send the process to the I/O queue it is destined for
        sendToIoQueue( &(run_state->currently_running_process), device_set,
                       activity_log );

        // get one from the queue if possible
        if( !is_Heap_empty( ready_queue ) )
        {
            // pop the item out of the queue
            run_state->currently_running_process =
                remove_PCB_from_Heap( ready_queue );
        }
        // case: there are no items to remove from the queue
            // leave the run state empty, with no process running
    }

        // now we will either have a process ready for the CPU or all
        // processes will be doing their I/O operations
        // (or the simulator run will be just about over)
}
Esempio n. 2
0
 void increment()
 {
     return boost::fusion::for_each(iterators_,
         increment_iterator());
 }