Skip to content

Commit 9e646c3

Browse files
committed
Fix Windows CI: timespec guard + server stdatomic/pthread shim
1 parent 6a403cf commit 9e646c3

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

quant.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ typedef volatile long atomic_int;
144144
#ifndef CLOCK_MONOTONIC
145145
#define CLOCK_MONOTONIC 1
146146
#endif
147+
#ifndef _TIMESPEC_DEFINED
148+
#define _TIMESPEC_DEFINED
147149
struct timespec { long tv_sec; long tv_nsec; };
150+
#endif
148151
static inline int clock_gettime(int id, struct timespec* ts) {
149152
(void)id; LARGE_INTEGER f, c;
150153
QueryPerformanceFrequency(&f); QueryPerformanceCounter(&c);

src/server/tq_server.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,26 @@
1818
#include <string.h>
1919
#include <stdarg.h>
2020
#include <stdbool.h>
21+
#if defined(_MSC_VER)
22+
#include <intrin.h>
23+
typedef volatile long atomic_int;
24+
#define atomic_store(p, v) _InterlockedExchange((p), (v))
25+
#define atomic_load(p) _InterlockedCompareExchange((p), 0, 0)
26+
#else
2127
#include <stdatomic.h>
28+
#endif
2229
#include <signal.h>
2330
#include <errno.h>
2431
#include <time.h>
32+
#ifdef _WIN32
33+
#include <windows.h>
34+
#define pthread_mutex_t SRWLOCK
35+
#define PTHREAD_MUTEX_INITIALIZER SRWLOCK_INIT
36+
#define pthread_mutex_lock(m) AcquireSRWLockExclusive(m)
37+
#define pthread_mutex_unlock(m) ReleaseSRWLockExclusive(m)
38+
#else
2539
#include <pthread.h>
40+
#endif
2641
#include <unistd.h>
2742
#include <sys/socket.h>
2843
#include <sys/types.h>

0 commit comments

Comments
 (0)