-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.c
executable file
·52 lines (41 loc) · 1.02 KB
/
scheduler.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
46
47
48
49
50
51
52
/**
* Immortal Operating System - immortalOS
*
*/
#include "scheduler.h"
extern u_int tasks_installed;
extern u_int task_running;
extern tcb_t F_APTOS[MAX_TASKS];
u_int contagemR()
{
u_int x = 0;
for (int i = 1; i < MAX_TASKS ; i++)
{
if (F_APTOS[i].task_state == READY) x++;
}
return x;
}
u_int rr_scheduler()
{
u_int next_task_to_run = 0;
u_int j = task_running;
u_int cont = contagemR();
PORTBbits.RB0 = ~LATBbits.LATB0;
do {
j++;
next_task_to_run = (j) % tasks_installed;
} while (F_APTOS[next_task_to_run].task_state != READY || (cont>0 && next_task_to_run == 0));
return next_task_to_run;
}
u_int prior_scheduler()
{
u_int next_task_to_run = 0, i;
PORTBbits.RB0 = ~LATBbits.LATB0;
for (i = 1; i < tasks_installed; i++) {
if (F_APTOS[next_task_to_run].task_prior > F_APTOS[i].task_prior) {
if (F_APTOS[i].task_state == READY)
next_task_to_run = i;
}
}
return next_task_to_run;
}