mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Add HPET support, create clock class
Create a clock class which can be queried for current timestamp in nanoseconds. Also implements a simple HPET class as one possible clock source. Tags: time
This commit is contained in:
22
src/kernel/clock.cpp
Normal file
22
src/kernel/clock.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "clock.h"
|
||||
|
||||
clock * clock::s_instance = nullptr;
|
||||
|
||||
clock::clock(uint64_t rate, clock::source source_func, void *data) :
|
||||
m_rate(rate),
|
||||
m_data(data),
|
||||
m_source(source_func)
|
||||
{
|
||||
// TODO: make this atomic
|
||||
if (s_instance == nullptr)
|
||||
s_instance = this;
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
clock::spinwait(uint64_t ns) const
|
||||
{
|
||||
uint64_t when = m_source(m_data) + ns;
|
||||
while (value() < when);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user