-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpump.h
More file actions
87 lines (80 loc) · 2.04 KB
/
Copy pathpump.h
File metadata and controls
87 lines (80 loc) · 2.04 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
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
#include <vector>
#include <queue>
#include "types.h"
class ProcessPump
{
private:
std::vector<proc_data_t> processes;
std::vector<proc_data_t>::const_iterator iter;
std::vector<proc_data_t>::const_iterator iter_end;
std::queue<proc_data_t> que;
int offset = 0;
int time = 0;
int loc = 0;
int list_exhausted = 0;
// check what processes have come in at this time
// add them to the queue
int queueProcesses()
{
// Recursion guard clause
if (list_exhausted)
return 0; // could return -1
if (time == (*iter).arrival_time)
{
// Last element
if (iter == iter_end)
{
list_exhausted = 1;
}
que.push(*iter); // Push an item to the queue
++iter;
queueProcesses();
}
return que.size();
}
public:
/// @brief Constructor
/// @param sorted_vec sorted vector of processes
ProcessPump(const std::vector<proc_data_t> &sorted_vec)
{
processes = sorted_vec; // Make a copy
iter = processes.cbegin();
iter_end = processes.cend() - 1;
time = 0;
}
/// @brief ### Are there processes ready?
/// @returns -1 if processes have been exhausted |
/// @returns 0 if nothing available |
/// @returns > 0 if there are processes waititing
int check()
{
if (list_exhausted == 1)
return -1;
else
{
int check = queueProcesses();
return check;
}
}
/// @brief Return processes waiting to be scheduled
/// @return std::queue<proc_data_t>
std::queue<proc_data_t> retrieveProcesses()
{
return que;
}
// Call once per tick
// This will clear the queue and increment internal timer
void advance()
{
if (list_exhausted)
return;
while (!que.empty())
{
que.pop();
}
time++;
}
// ProcessPump operator++(){
// advance();
// }
};