Skip to content

Commit 7c29df8

Browse files
committed
Implement z_clock_advance for windows port
1 parent 7658248 commit 7c29df8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/system/windows/system.c

+36
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,42 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) {
237237
return (unsigned long)elapsed;
238238
}
239239

240+
void z_clock_advance_us(z_clock_t *clock, unsigned long duration) {
241+
LARGE_INTEGER frequency;
242+
QueryPerformanceFrequency(&frequency); // ticks per second
243+
244+
// Hardware not supporting QueryPerformanceFrequency
245+
if (frequency.QuadPart == 0) {
246+
return;
247+
}
248+
double ticks = (double)duration * frequency.QuadPart / 1000000.0;
249+
clock->QuadPart += (LONGLONG)ticks;
250+
}
251+
252+
void z_clock_advance_ms(z_clock_t *clock, unsigned long duration) {
253+
LARGE_INTEGER frequency;
254+
QueryPerformanceFrequency(&frequency); // ticks per second
255+
256+
// Hardware not supporting QueryPerformanceFrequency
257+
if (frequency.QuadPart == 0) {
258+
return;
259+
}
260+
double ticks = (double)duration * frequency.QuadPart / 1000.0;
261+
clock->QuadPart += (LONGLONG)ticks;
262+
}
263+
264+
void z_clock_advance_s(z_clock_t *clock, unsigned long duration) {
265+
LARGE_INTEGER frequency;
266+
QueryPerformanceFrequency(&frequency); // ticks per second
267+
268+
// Hardware not supporting QueryPerformanceFrequency
269+
if (frequency.QuadPart == 0) {
270+
return;
271+
}
272+
double ticks = (double)duration * frequency.QuadPart;
273+
clock->QuadPart += (LONGLONG)ticks;
274+
}
275+
240276
/*------------------ Time ------------------*/
241277
z_time_t z_time_now(void) {
242278
z_time_t now;

0 commit comments

Comments
 (0)