Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.

Commit fdf4e52

Browse files
committed
fix(test_stress): add Windows timing and process ID support
- Replace clock_gettime with QueryPerformanceCounter on Windows - Map getpid() to _getpid() on Windows - Suppress MSVC getenv warnings with _CRT_SECURE_NO_WARNINGS - Add windows.h and process.h includes for Windows platform Fixes Windows build errors for CLOCK_MONOTONIC and getpid undefined.
1 parent 0ca729a commit fdf4e52

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/c/test_stress.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626

2727
/* Platform-specific headers for file operations */
2828
#ifdef _WIN32
29+
#define _CRT_SECURE_NO_WARNINGS /* Suppress MSVC warnings for getenv */
2930
#include <io.h>
31+
#include <process.h> /* For _getpid */
3032
#include <sys/types.h>
3133
#include <sys/stat.h>
34+
#include <windows.h> /* For QueryPerformanceCounter */
3235
#define unlink _unlink
36+
#define getpid _getpid
3337
#else
3438
#include <sys/stat.h>
3539
#include <unistd.h>
@@ -113,9 +117,23 @@ static void cleanup_temp_files(void) {
113117
** Get current time in milliseconds (monotonic)
114118
*/
115119
static double get_time_ms(void) {
120+
#ifdef _WIN32
121+
static LARGE_INTEGER frequency;
122+
static int initialized = 0;
123+
LARGE_INTEGER counter;
124+
125+
if (!initialized) {
126+
QueryPerformanceFrequency(&frequency);
127+
initialized = 1;
128+
}
129+
130+
QueryPerformanceCounter(&counter);
131+
return (double)counter.QuadPart * 1000.0 / (double)frequency.QuadPart;
132+
#else
116133
struct timespec ts;
117134
clock_gettime(CLOCK_MONOTONIC, &ts);
118135
return (double)ts.tv_sec * 1000.0 + (double)ts.tv_nsec / 1000000.0;
136+
#endif
119137
}
120138

121139
/*

0 commit comments

Comments
 (0)