-
Notifications
You must be signed in to change notification settings - Fork 0
/
MLFQ.h
97 lines (66 loc) · 1.88 KB
/
MLFQ.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#ifndef MLFQ_H
#define MLFQ_H
#include "priQ.h"
int MLFQ_quanta = 2;
int MLFQ_start;
bool MLFQ_addProcess(void *type,process *proc);
bool MLFQ_preempt(void *type);
process* MLFQ_getNextProcess(void *type);
bool MLFQ_removeProcess(void *type,process *proc);
bool MLFQ_free(void *type);
void MLFQcast(void *type) {
}
bool MLFQ_init(scheduling_algo * curr_algo){
if(!curr_algo) return 0;
priQ* MLFQqueue = (priQ *)malloc(sizeof(priQ));
priQcreate(MLFQqueue, 50);
*curr_algo = (scheduling_algo){
MLFQqueue,
MLFQ_addProcess,
MLFQ_preempt,
MLFQ_getNextProcess,
MLFQ_removeProcess,
MLFQ_free,
};
return 1;
}
bool MLFQ_addProcess(void *type,process *p){
priQ *queue = (priQ *)type;
bool success = priQenqueue(queue,p);
return success;
}
process* MLFQ_getNextProcess(void *type){
priQ* queue = (priQ *) type;
process* nextProcess = priQpeek(queue);
return nextProcess;
}
bool MLFQ_preempt(void *type){
int clk = getClk();
if(curentProcess == NULL){
MLFQ_start = clk;
return true;
}
priQ *queue = (priQ *) type;
if(clk - MLFQ_start >= MLFQ_quanta){
MLFQ_start = clk;
priQremove(queue,curentProcess);
if(curentProcess->priority != 10) curentProcess->priority++;
if(curentProcess->remainingtime > 0) priQenqueue(queue,curentProcess);
return (queue->capacity > 1) && (curentProcess->remainingtime > 0);
}
return false;
}
// Removes the process from the pri queue
bool MLFQ_removeProcess(void *type,process *p){
priQ *queue = (priQ *) type;
bool success = priQremove(queue,p);
return success;
}
// Frees the alocated resources created by the algorithm
bool MLFQ_free(void *type){
priQ *queue = (priQ *)type;
bool succes = priQfree(queue);
return succes;
}
#endif