Skip to content

Commit

Permalink
Implement z_clock_advance for windows port
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Dec 7, 2024
1 parent 7658248 commit 7c29df8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/system/windows/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,42 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) {
return (unsigned long)elapsed;
}

void z_clock_advance_us(z_clock_t *clock, unsigned long duration) {
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency); // ticks per second

// Hardware not supporting QueryPerformanceFrequency
if (frequency.QuadPart == 0) {
return;
}
double ticks = (double)duration * frequency.QuadPart / 1000000.0;
clock->QuadPart += (LONGLONG)ticks;
}

void z_clock_advance_ms(z_clock_t *clock, unsigned long duration) {
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency); // ticks per second

// Hardware not supporting QueryPerformanceFrequency
if (frequency.QuadPart == 0) {
return;
}
double ticks = (double)duration * frequency.QuadPart / 1000.0;
clock->QuadPart += (LONGLONG)ticks;
}

void z_clock_advance_s(z_clock_t *clock, unsigned long duration) {
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency); // ticks per second

// Hardware not supporting QueryPerformanceFrequency
if (frequency.QuadPart == 0) {
return;
}
double ticks = (double)duration * frequency.QuadPart;
clock->QuadPart += (LONGLONG)ticks;
}

/*------------------ Time ------------------*/
z_time_t z_time_now(void) {
z_time_t now;
Expand Down

0 comments on commit 7c29df8

Please sign in to comment.