Files
jsix/src/kernel/clock.cpp
Justin C. Miller 31289436f5 [kernel] Use PAUSE in spinwait
Using PAUSE in a tight loop allows other logical cores on the same
physical core to make use of more of the core's resources.
2021-02-07 23:52:06 -08:00

23 lines
387 B
C++

#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 us) const
{
uint64_t when = value() + us;
while (value() < when) asm ("pause");
}