diff --git a/kernel/include/kernel/Timer/PIT.h b/kernel/include/kernel/Timer/PIT.h index 09025ccf85..36703636f5 100644 --- a/kernel/include/kernel/Timer/PIT.h +++ b/kernel/include/kernel/Timer/PIT.h @@ -14,7 +14,6 @@ namespace Kernel static BAN::ErrorOr> create(); virtual uint64_t ms_since_boot() const override; - virtual void sleep(uint64_t) const override; private: void initialize(); diff --git a/kernel/include/kernel/Timer/Timer.h b/kernel/include/kernel/Timer/Timer.h index 8117102ea6..56e5d5198c 100644 --- a/kernel/include/kernel/Timer/Timer.h +++ b/kernel/include/kernel/Timer/Timer.h @@ -12,7 +12,6 @@ namespace Kernel public: virtual ~Timer() {}; virtual uint64_t ms_since_boot() const = 0; - virtual void sleep(uint64_t) const = 0; }; class TimerHandler @@ -35,7 +34,7 @@ namespace Kernel private: uint64_t m_boot_time { 0 }; BAN::UniqPtr m_rtc; - BAN::Vector> m_timers; + BAN::UniqPtr m_timer; }; } \ No newline at end of file diff --git a/kernel/kernel/Timer/PIT.cpp b/kernel/kernel/Timer/PIT.cpp index 1450ae1673..003893834c 100644 --- a/kernel/kernel/Timer/PIT.cpp +++ b/kernel/kernel/Timer/PIT.cpp @@ -60,14 +60,4 @@ namespace Kernel return s_system_time; } - void PIT::sleep(uint64_t ms) const - { - if (ms == 0) - return; - uint64_t wake_time = s_system_time + ms; - Kernel::Scheduler::get().set_current_thread_sleeping(wake_time); - if (s_system_time < wake_time) - dwarnln("sleep woke {} ms too soon", wake_time - s_system_time); - } - } diff --git a/kernel/kernel/Timer/Timer.cpp b/kernel/kernel/Timer/Timer.cpp index c0a9cdc9a6..a9340051f0 100644 --- a/kernel/kernel/Timer/Timer.cpp +++ b/kernel/kernel/Timer/Timer.cpp @@ -1,5 +1,6 @@ -#include +#include #include +#include namespace Kernel { @@ -35,21 +36,27 @@ namespace Kernel dwarnln("PIT: {}", res.error()); else { - MUST(m_timers.emplace_back(BAN::move(res.release_value()))); + m_timer = res.release_value(); dprintln("PIT initialized"); + return; } - ASSERT(!m_timers.empty()); + Kernel::panic("Could not initialize any timer"); } uint64_t TimerHandler::ms_since_boot() const { - return m_timers.front()->ms_since_boot(); + return m_timer->ms_since_boot(); } void TimerHandler::sleep(uint64_t ms) const { - return m_timers.front()->sleep(ms); + if (ms == 0) + return; + uint64_t wake_time = ms_since_boot() + ms; + Scheduler::get().set_current_thread_sleeping(wake_time); + if (ms_since_boot() < wake_time) + dwarnln("sleep woke {} ms too soon", wake_time - ms_since_boot()); } uint64_t TimerHandler::get_unix_timestamp()