-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyscheduler.h
38 lines (32 loc) · 1.54 KB
/
myscheduler.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
#pragma once
//myschedule.h
/* Students need to define their own data structure to contain
and access objects from 'thread class'. The 'CreateThread()'
function should insert the threads into the student defined
data structure after creating them.
They are allowed to add any additional functionality (only
declaration in this file, define in 'myschedule.cpp')
which they might find helpful.*/
#include "scheduler.h"
#include <vector>
//Define your data structure here.
struct ThreadsStatus {
ThreadDescriptorBlock *thread; // thread pointer
bool isScheduled; // whether in queue or already scheduled
unsigned int CPU_id; // if scheduled, record the id of CPU that handles this thread
bool isRunning; // true if thread is currently being processed by a cpu
};
class MyScheduler : public Scheduler {
public:
MyScheduler(Policy p, unsigned int n); // constructor
~MyScheduler(); // destructor
bool Dispatch() override; //Function to implement scheduling policy and to keep a check on processed threads
void CreateThread(int arriving_time, int remaining_time, int priority, int tid) override; //Function to create threads and insert them in student defined data structure
// variables
vector<ThreadsStatus> threadVector; // vector to store all threads
vector<ThreadsStatus> orderedVector; // vector to store ordered threads
unsigned int num_scheduledCPU; // used for checking available cpu
// additional functions
void push_to_ordered_list(ThreadsStatus *thread);
void clear_CPU();
};