try fix windows compile errors: undefined c11 atomic_flag_*()

This commit is contained in:
mqy 2023-04-17 15:59:06 +08:00
parent 6b515403c8
commit cba49ad48b

16
ggml.c
View file

@ -33,19 +33,27 @@
typedef volatile LONG atomic_int; typedef volatile LONG atomic_int;
typedef atomic_int atomic_bool; typedef atomic_int atomic_bool;
static void atomic_store(atomic_int* ptr, LONG val) { static inline void atomic_store(atomic_int* ptr, LONG val) {
InterlockedExchange(ptr, val); InterlockedExchange(ptr, val);
} }
static LONG atomic_load(atomic_int* ptr) { static inline LONG atomic_load(atomic_int* ptr) {
return InterlockedCompareExchange(ptr, 0, 0); return InterlockedCompareExchange(ptr, 0, 0);
} }
static LONG atomic_fetch_add(atomic_int* ptr, LONG inc) { static inline LONG atomic_fetch_add(atomic_int* ptr, LONG inc) {
return InterlockedExchangeAdd(ptr, inc); return InterlockedExchangeAdd(ptr, inc);
} }
static LONG atomic_fetch_sub(atomic_int* ptr, LONG dec) { static inline LONG atomic_fetch_sub(atomic_int* ptr, LONG dec) {
return atomic_fetch_add(ptr, -(dec)); return atomic_fetch_add(ptr, -(dec));
} }
static inline LONG atomic_flag_test_and_set(atomic_int* ptr) {
return InterlockedCompareExchange(ptr, 1, 0);
}
static inline LONG atomic_flag_test_clear(atomic_int* ptr) {
return InterlockedExchange(ptr, 0)
}
typedef HANDLE pthread_t; typedef HANDLE pthread_t;
typedef DWORD thread_ret_t; typedef DWORD thread_ret_t;