diff options
| author | MDBijman <matthijs@bijman.org> | 2017-01-24 12:15:26 +0100 |
|---|---|---|
| committer | MDBijman <matthijs@bijman.org> | 2017-01-24 12:15:26 +0100 |
| commit | 070ce923574dcc57435cb3fb2dfe86b6a38cd249 (patch) | |
| tree | ffd69a842ac4ad22aaf7161f923b9f0b47c7147a /Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h | |
Initial code commit with organized dependencies
Diffstat (limited to 'Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h')
| -rw-r--r-- | Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h new file mode 100644 index 00000000..0cac0dfa --- /dev/null +++ b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h @@ -0,0 +1,37 @@ +#pragma once +#include "Scheduler.h" +#include <algorithm> + +namespace Simulation +{ + class FirstInFirstOutScheduler : public Scheduler + { + protected: + ~FirstInFirstOutScheduler() + { + } + + public: + /* + Distribute workloads according to the FIFO principle + */ + void schedule(std::vector<std::reference_wrapper<Modeling::Machine>>& machines, std::vector<Workload*> workloads) override + { + if (workloads.size() == 0) + return; + + // Find the first workload with dependencies finished + int index = 0; + while(!workloads.at(index)->dependencyFinished) + index = (++index) % workloads.size(); + + std::for_each( + machines.begin(), + machines.end(), + [index, &workloads](std::reference_wrapper<Modeling::Machine>& machine) { + machine.get().giveTask(workloads.at(index)); + } + ); + } + }; +} |
