-
Notifications
You must be signed in to change notification settings - Fork 0
/
disastrOS_schedule.c
45 lines (37 loc) · 1.28 KB
/
disastrOS_schedule.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include "disastrOS.h"
#include "disastrOS_syscalls.h"
// replaces the running process with the next one in the ready list
void internal_schedule() {
if(DEBUG==1) printf("SONO NELLA INTERNAL_SCHEDULE\n");
if (running) {
disastrOS_debug("PREEMPT - %d ->", running->pid);
}
// at least one process should be in the running queue
// if not, no preemption occurs
// Sveglio i processi in base ai timer dati e li metto nella ready list
TimerItem* elapsed_timer=0;
PCB* previous_pcb=0;
while( (elapsed_timer=TimerList_current(&timer_list, disastrOS_time)) ){
PCB* pcb_to_wake=elapsed_timer->pcb;
List_detach(&waiting_list, (ListItem*) pcb_to_wake);
pcb_to_wake->status=Ready;
pcb_to_wake->timer=0;
List_insert(&ready_list, (ListItem*) previous_pcb, (ListItem*) pcb_to_wake);
previous_pcb=pcb_to_wake;
TimerList_removeCurrent(&timer_list);
}
if (ready_list.first){
PCB* next_process=(PCB*) List_detach(&ready_list, ready_list.first);
running->status=Ready;
List_insert(&ready_list, ready_list.last, (ListItem*) running);
next_process->status=Running;
running=next_process;
}
//disastrOS_printStatus();
if (running) {
disastrOS_debug(" %d\n", running->pid);
}
}