diff options
| author | Julian Blake Kongslie | 2022-10-15 14:12:31 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-15 14:12:31 -0700 |
| commit | ecf940e34b42f78f9651a73e8bcd0c6dc3c75cb5 (patch) | |
| tree | 36a290bf7a6ed585cf040964c8e7481f4df1d631 /infra/queue.h | |
| parent | Move shared_bus into arbiter (diff) | |
| download | biggolf-ecf940e34b42f78f9651a73e8bcd0c6dc3c75cb5.tar.xz | |
Depend on external nanosim dependency.
Diffstat (limited to '')
| -rw-r--r-- | infra/queue.h | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/infra/queue.h b/infra/queue.h deleted file mode 100644 index 1e490bc..0000000 --- a/infra/queue.h +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cassert> | ||
| 4 | #include <deque> | ||
| 5 | #include <optional> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "infra/port.h" | ||
| 9 | #include "infra/sim.h" | ||
| 10 | |||
| 11 | namespace infra { | ||
| 12 | template<typename T, unsigned int size> struct queue : public sim { | ||
| 13 | port<T> input; | ||
| 14 | port<T> *output = nullptr; | ||
| 15 | std::deque<T> elements; | ||
| 16 | |||
| 17 | void clock() { | ||
| 18 | if (input.can_read() && elements.size() < size) { | ||
| 19 | auto x = input.read(); | ||
| 20 | elements.emplace_back(std::move(x)); | ||
| 21 | } | ||
| 22 | if (output->can_write() && !elements.empty()) { | ||
| 23 | auto &x = elements.front(); | ||
| 24 | output->write(std::move(x)); | ||
| 25 | elements.pop_front(); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | } | ||
