-
Notifications
You must be signed in to change notification settings - Fork 2
/
scheduler.h
74 lines (72 loc) · 2.84 KB
/
scheduler.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
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
#define N (int)100000
#define MAX_STRIDE 10000 // Set a maximum stride value
extern std::vector<std::vector<std::string>> output;
// priority_queue<process,compare>
struct process
{
string process_name;
int process_idx; // index in the array
int arrive_time;
int turn_around_time;
int complete_time;
int time_consumed; // current phase take kam second
int n_phases; // kam phase
int phase_idx;
int last_processor; // last processor work on
vector<pair<int, bool>> phases; //
int state; // current state
int priority;
int current_brust_time;
int qunta; // to calculate time in MLFQ
int tickets;
int pass_value;
int stride;
};
struct CompareProcess
{
const process *data;
CompareProcess(const process *d) : data(d) {}
bool operator()(int a, int b) const
{
return (data[a].current_brust_time - data[a].time_consumed) > (data[b].current_brust_time - data[b].time_consumed);
}
};
struct CompareProcesspriority
{
const process *data;
CompareProcesspriority(const process *d) : data(d) {}
bool operator()(int a, int b) const
{
return data[a].priority > data[b].priority;
}
};
struct CompareProcessstride
{
const process *data;
CompareProcessstride(const process *d) : data(d) {}
bool operator()(int a, int b) const
{
return data[a].pass_value > data[b].pass_value;
}
};
bool comareByPriority(const process &p1, const process &p2); // ascending order
bool comparedByBurst(const process &p1, const process &p2);
void print(int endtime, process processes[], int n);
void IO_handler(int n, process processes[], queue<int> &my_queue, int &finised_processes, int t);
void IO_handler_MLFQ(int n, process processes[], queue<int> my_queue[], int &finised_processes, int t);
void IO_handler_bypq(int n, process processes[], priority_queue<int, vector<int>, CompareProcess> &my_queue, int &finised_processes, int t);
void IO_handler_bypq_priority(int n, process processes[], priority_queue<int, vector<int>, CompareProcesspriority> &my_queue, int &finised_processes, int t);
void IO_handler_bypq_stride(int n, process processes[], priority_queue<int, vector<int>, CompareProcessstride> &my_queue, int &finised_processes, int t);
void match_prefrences(int processor[], int WillGoToTheQ[], process processes[]);
void changeThePriorty(int n, process processes[]);
void MLFQ(int n, process processes[]);
void round_robin(int n, process processes[]);
void SJF(int size, process processes[]);
void STCF(int size, process processes[]);
void FCFS(int size, process processes[]);
void Priority(int size, process processes[]);
void strideScheduler(int n, process processes[]);
int calculateTickets(process p);