From b1cf9e5dfbc8967bd7cb2a22ec1e5e521f4e0e6e Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Wed, 31 Jul 2024 13:36:53 -0400 Subject: add clock --- kernel/include/hilbert/kernel/timer.hpp | 18 ++++++++++++++++++ kernel/include/hilbert/kernel/utility.hpp | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 kernel/include/hilbert/kernel/timer.hpp (limited to 'kernel/include') diff --git a/kernel/include/hilbert/kernel/timer.hpp b/kernel/include/hilbert/kernel/timer.hpp new file mode 100644 index 0000000..f4ce17e --- /dev/null +++ b/kernel/include/hilbert/kernel/timer.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace hilbert::kernel::timer { + + void init_timer(); + + //"mibiseconds" (1 second / 1024) since january 1st 2000 + extern uint64_t current_time; + + //when current_time >= sleeping_until, puts thread into paused threads + void register_sleeping_thread( + uint64_t sleeping_until, application::thread *thread); + + void on_timer_interrupt(); + +} diff --git a/kernel/include/hilbert/kernel/utility.hpp b/kernel/include/hilbert/kernel/utility.hpp index a21d3fe..b0ced32 100644 --- a/kernel/include/hilbert/kernel/utility.hpp +++ b/kernel/include/hilbert/kernel/utility.hpp @@ -126,6 +126,25 @@ namespace hilbert::kernel::utility { last = n; } + //if other == 0, then insert at the end + void insert_before(value_t &&value, node *other) { + node *n = new node {}; + n->value = value; + n->next = other; + if (other) { + n->prev = other->prev; + other->prev = n; + } + else { + n->prev = last; + last = n; + } + if (n->prev) + n->prev->next = n; + else + first = n; + } + void clear() { if (first) { for (node *n = first->next; n; n = n->next) -- cgit v1.2.3