diff options
Diffstat (limited to '')
| -rw-r--r-- | sim/sim.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/sim/sim.h b/sim/sim.h new file mode 100644 index 0000000..399832a --- /dev/null +++ b/sim/sim.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <map> | ||
| 5 | #include <set> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | namespace sim { | ||
| 9 | |||
| 10 | struct Schedulable; | ||
| 11 | |||
| 12 | struct Scheduler { | ||
| 13 | std::set<Schedulable *> unsorted_schedulables; | ||
| 14 | std::vector<Schedulable *> sorted_schedulables; | ||
| 15 | bool sort_needed = false; | ||
| 16 | |||
| 17 | std::multimap<Schedulable *, Schedulable *> constraints; | ||
| 18 | |||
| 19 | Schedulable *current_schedulable = nullptr; | ||
| 20 | std::uint64_t now = 0; | ||
| 21 | |||
| 22 | void add_schedulable(Schedulable *schedulable); | ||
| 23 | void remove_schedulable(Schedulable *schedulable); | ||
| 24 | |||
| 25 | void constrain(Schedulable *prior, Schedulable *later); | ||
| 26 | |||
| 27 | void topo_sort(std::set<Schedulable *> &live, std::set<Schedulable *> &waiting, Schedulable *candidate); | ||
| 28 | void sort(); | ||
| 29 | |||
| 30 | void clock(); | ||
| 31 | }; | ||
| 32 | |||
| 33 | struct Schedulable { | ||
| 34 | Scheduler &scheduler; | ||
| 35 | |||
| 36 | Schedulable(Scheduler &scheduler); | ||
| 37 | virtual ~Schedulable(); | ||
| 38 | |||
| 39 | virtual void clock() = 0; | ||
| 40 | |||
| 41 | std::uint64_t now(); | ||
| 42 | }; | ||
| 43 | |||
| 44 | } | ||
