diff options
Diffstat (limited to 'src/task.h')
-rw-r--r-- | src/task.h | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/src/task.h b/src/task.h deleted file mode 100644 index 0d59bb1..0000000 --- a/src/task.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -/** - * Representation of a task in the system - */ -struct Task { - const char *name; - int id; - int priority; - int burst; -}; - -#ifdef __cplusplus -template <typename T> struct Queue { - struct Item { - Item(T *p_node) : node(p_node) {} - T *node; - Item *next = nullptr; - - [[nodiscard]] bool - operator==(const T *other) const - { - return node == other; - } - }; - - ~Queue() noexcept - { - for (auto *it = head; it != nullptr;) { - auto *current = it; - it = it->next; - delete current->node; - delete current; - } - } - - /// Insert item at the end of the queue - void - insert(T *item) - { - if (head == nullptr) { - head = new Item(item); - tail = head; - } - else { - tail->next = new Item(item); - tail = tail->next; - } - } - - void - remove(T *item) - { - if (head == nullptr) return; - if (item == head->node) { - auto *it = head; - head = head->next; - if (*tail == item) tail = nullptr; - delete it; - return; - } - - Item *prev = nullptr; - for (auto *it = head; it != nullptr; it = it->next) { - if (it->node == item) { - if (prev) { prev->next = it->next; } - if (tail == it) { tail = prev; } - delete it; - return; - } - prev = it; - } - } - - Item *head = nullptr; - Item *tail = nullptr; -}; -#endif |