/* The main scheduling routine */
void schedule(event_type event) {
    static int first = 1;

    /* Set initial variables */
    if (first) {
        mem_init(memory);
        finale = my_finale;
        first = 0;
    }

    switch (event) {
        case NewProcess_event:
            GiveMemory();
            break;
        case Time_event:
        case IO_event:
            CPU_scheduler();
            break;
        case Ready_event:
            break;
        case Finish_event:
            ReclaimMemory();
            GiveMemory();
            CPU_scheduler();
            break;
        default:
            printf("I cannot handle event nr. %d\n", event);
            break;
    }
}
示例#2
0
文件: cpu.c 项目: DuyH/TCSS422
void CPU_pseudo_isr(CPU_p cpu, int PC) {
    if (cpu->currentProcess != NULL) {
        fprintf(file, "Timer interrupt...\n");

        // 1. Change the state of the running process to interrupted
        PCB_set_state(cpu->currentProcess, interrupted);

        // 2. Save the CPU state to the PCB
        PCB_set_pc(cpu->currentProcess, cpu->pc);

        fprintf(file, "Process interrupted: %s",
                PCB_toString(cpu->currentProcess));

        //Replace PC of CPU will value stored in systemStack
        cpu->pc = cpu->sysStack;

        //cpu->pc = CPU_pop_sysStack(cpu);

        // 3. "Do an up-call" to the scheduler
        CPU_scheduler(cpu, timer, PC);

    } else {
        fprintf(file, "No process currently running. Normal interrupt...\n");
        CPU_scheduler(cpu, normal, PC);
    }

    return;
}