commit ce9b0c9

uint  ·  2026-06-22 22:03:12 +0000 UTC
parent c871a00
Implement maus_get_time_ns for win32
1 files changed,  +17, -2
+17, -2
 1@@ -1,6 +1,7 @@
 2 #if !defined(BACKEND_WIN)
 3 #define _POSIX_C_SOURCE 199309L
 4-#else /* windows */
 5+#else
 6+#include <windows.h>
 7 #endif
 8 
 9 #include <stdarg.h>
10@@ -29,10 +30,24 @@ void maus_die(const char* fmt, ...)
11 }
12 
13 uint64_t maus_get_time_ns(void)
14-{ /* TODO unix only right now */
15+{
16+#if !defined(WIN32)
17 	struct timespec ts;
18 	clock_gettime(CLOCK_MONOTONIC, &ts);
19 	return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
20+#else
21+	static LARGE_INTEGER frequency = {0};
22+	if (frequency.QuadPart == 0)
23+		QueryPerformanceFrequency(&frequency);
24+
25+	LARGE_INTEGER counter;
26+	QueryPerformanceCounter(&counter);
27+
28+	uint64_t sec = counter.QuadPart / frequency.QuadPart;
29+	uint64_t rem = counter.QuadPart % frequency.QuadPart;
30+
31+	return (sec * 1000000000ULL) + ((rem * 1000000000ULL) / frequency.QuadPart);
32+#endif
33 }
34 
35 void maus_log(FILE* fd, const char* fmt, ...)