-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.c
More file actions
62 lines (49 loc) · 1.69 KB
/
kernel.c
File metadata and controls
62 lines (49 loc) · 1.69 KB
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
53
54
55
56
57
58
59
60
// *******************************************************
//
// kernel.c
//
// A round robin kernel implementation
//
// Tom Rizzi, Euan Robinson, Satwik Meravanage
// Last modified: 21 May 2021
//
// *******************************************************
//*****************************************************************************
// Includes
//*****************************************************************************
#include "kernel.h"
#include "timings.h"
//*****************************************************************************
// Checks the process needs to be run.
//*****************************************************************************
bool shouldRunProcess(Process process)
{
return (process.lastRunRef == 0 || process.rate == KERNEL_MAX_RATE || shouldBeRun(process.lastRunRef, process.rate));
}
//*****************************************************************************
// Runs the main round robin loop.
// Takes the following parameters...
//
// processes: List of processes to run.
// n: Number of processes in the list of
//*****************************************************************************
void runKernel(Process processes[], int n)
{
// Set the initial last run reference
int i = 0;
for (i = 0; i < n; i++) {
processes[i].lastRunRef = 0;
}
// Run the main schedule
while (1) {
for (i = 0; i < n; i++) {
// Check if this process should be run
if (shouldRunProcess(processes[i])) {
// Reset the reference time
processes[i].lastRunRef = getCurTime();
// Run the actual function
processes[i].handler();
}
}
}
}