Skip to content

Commit 183e69f

Browse files
committed
feat: add cross-platform support to now_ms_mono using QueryPerformanceCounter for Windows
1 parent 6229389 commit 183e69f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/class.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,21 @@ void ark_log(arkilian *db, ark_log_level_t level, const char *fmt, ...) {
300300
}
301301

302302
// Monotonic milliseconds, for heartbeats and latency instrumentation.
303+
// POSIX uses clock_gettime(CLOCK_MONOTONIC); Windows uses
304+
// QueryPerformanceCounter (high-resolution, monotonic). Both return a
305+
// millisecond value suitable for heartbeat age computation.
303306
static long long now_ms_mono(void) {
307+
#ifndef _WIN32
304308
struct timespec ts;
305309
clock_gettime(CLOCK_MONOTONIC, &ts);
306310
return (long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL;
311+
#else
312+
static LARGE_INTEGER freq = {0};
313+
if (freq.QuadPart == 0) QueryPerformanceFrequency(&freq);
314+
LARGE_INTEGER count;
315+
QueryPerformanceCounter(&count);
316+
return (long long)(count.QuadPart * 1000LL / freq.QuadPart);
317+
#endif
307318
}
308319

309320
// ── libcurl one-time global init ────────────────────────────────────

0 commit comments

Comments
 (0)