forked from Bananymous/banan-os
Kernel: Move sleep() implementation to TimerHandler
This commit is contained in:
parent
aa0929614a
commit
ea4a70c3b3
|
@ -14,7 +14,6 @@ namespace Kernel
|
|||
static BAN::ErrorOr<BAN::UniqPtr<PIT>> create();
|
||||
|
||||
virtual uint64_t ms_since_boot() const override;
|
||||
virtual void sleep(uint64_t) const override;
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
|
|
@ -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<RTC> m_rtc;
|
||||
BAN::Vector<BAN::UniqPtr<Timer>> m_timers;
|
||||
BAN::UniqPtr<Timer> m_timer;
|
||||
};
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <kernel/Timer/Timer.h>
|
||||
#include <kernel/Scheduler.h>
|
||||
#include <kernel/Timer/PIT.h>
|
||||
#include <kernel/Timer/Timer.h>
|
||||
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue