-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltf_schedule.cpp
60 lines (53 loc) · 1.55 KB
/
ltf_schedule.cpp
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
#include "schedule.hpp"
#include "task.hpp"
schedule ltf_schedule(const std::vector<task> &tasks, const adj_list &graph)
{
schedule ltf;
std::vector<int> parent_tasks = parent_task_count(graph);
ready_list ready_tasks;
/*
Fill ready tasks with orphan tasks -
ones with no dependencies
*/
for (unsigned int i = 0; i < parent_tasks.size(); ++i) {
if (parent_tasks[i] == 0) {
ready_tasks.push(tasks[i]);
}
}
int last_lp = -1, last_hp = -1;
while (! ready_tasks.empty()) {
task ready = ready_tasks.top();
ready_tasks.pop();
if ((ltf.lpt() <= ltf.hpt()) && (ltf.lpt() + ready.lp_size() <= MAX_DUR)) {
// LP Slot is Free and current task will not exceed MAX_DUR
ltf.add_LP_slot(ready);
if (last_lp != -1) clear_tasks(ready_tasks, tasks, graph[last_lp], parent_tasks);
last_lp = ready.get_id();
if (ltf.lpt() >= ltf.hpt() && last_hp != -1) {
clear_tasks(ready_tasks, tasks, graph[last_hp], parent_tasks);
last_hp = -1;
}
} else {
// Add task to HP Slot
ltf.add_HP_slot(ready);
if (last_hp != -1) clear_tasks(ready_tasks, tasks, graph[last_hp], parent_tasks);
last_hp = ready.get_id();
if (ltf.hpt() >= ltf.lpt() && last_lp != -1) {
clear_tasks(ready_tasks, tasks, graph[last_lp], parent_tasks);
last_lp = -1;
}
}
if (ready_tasks.empty()) {
ltf.wait();
if (last_lp != -1) {
clear_tasks(ready_tasks, tasks, graph[last_lp], parent_tasks);
last_lp = -1;
}
if (last_hp != -1) {
clear_tasks(ready_tasks, tasks, graph[last_hp], parent_tasks);
last_hp = -1;
}
}
}
return ltf;
}