Possible optimization bug in sleep() function
Posted: Wed Feb 17, 2021 8:03 am
I recently made the advancement to program the PIT, and the first thing I wrote was a sleep() function.
It looks like this:
ms_clock is incremented by my PIT IRQ handler:
I stepped through the sleep() function with a debugger, and verified that the values were in fact correct. ms was 3000, and sys::chrono::ms_clock was 0 (to start).
Yet when stepping through the loop, it just skips by, no delay at all.
Could this be an optimization bug? Or am I at fault?
It looks like this:
Code: Select all
volatile uint64_t sys::chrono::ms_clock = 0;
void sys::chrono::sleep(volatile uint32_t ms)
{
ms_clock = 0;
while (ms_clock < ms);
ms_clock = 0;
}
Code: Select all
sys::chrono::ms_clock++;
milliseconds++;
if (milliseconds >= io::pit::frequency_hz)
{
milliseconds = 0;
seconds++;
}
Yet when stepping through the loop, it just skips by, no delay at all.
Could this be an optimization bug? Or am I at fault?