-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.cxx
54 lines (46 loc) · 1.74 KB
/
Loader.cxx
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
#include <fstream>
#include <algorithm>
#include <iostream>
#include "Loader.hxx"
/**
* Constructor
*/
Loader::Loader(std::list<Task*>* taskList, std::string fileName) :
loadedTasks(taskList) {
std::ifstream inFile;
inFile.open(fileName);
inFile.ignore(512,'\n');
//start time, length, deadline, priority, block period, blcok length
unsigned long start, length, deadline, priority, blockPeriod, blockLength;
while(inFile>>start) {
inFile>>length;
inFile>>deadline;
inFile>>priority;
inFile>>blockPeriod;
inFile>>blockLength;
unloadedTasks.push_back(new Task(length, start,deadline,
priority,blockPeriod,blockLength));
}
unloadedTasks.sort(
[](Task* a,Task* b){ return a->getSpawnTime() < b->getSpawnTime();});
}
/**
* Destructor
* Cleans up any unloaded tasks
*/
Loader::~Loader() {
std::for_each(unloadedTasks.begin(),unloadedTasks.end(),
[](Task* a){delete a;});
}
/**
* Iterates through unloaded tasks to check if any need to be loaded to active list
*/
void Loader::update(int time) {
//std::cout<<unloadedTasks.size()<<std::endl;
while(unloadedTasks.size() && (*unloadedTasks.begin())->getSpawnTime() <= time){ //non empty and first should spawn
(*unloadedTasks.begin())->setTimeStarted(time);
(*unloadedTasks.begin())->setTimeLastRun(time); //set task time started
loadedTasks->push_back(*unloadedTasks.begin()); //push task onto scheduler's queue
unloadedTasks.pop_front(); //pop from unloaded
}
}