From cba49ad48b29ccf5eb3cd47d6bb66999e171446e Mon Sep 17 00:00:00 2001 From: mqy Date: Mon, 17 Apr 2023 15:59:06 +0800 Subject: [PATCH] try fix windows compile errors: undefined c11 atomic_flag_*() --- ggml.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ggml.c b/ggml.c index 523d4019a..33ecc2e6d 100644 --- a/ggml.c +++ b/ggml.c @@ -33,19 +33,27 @@ typedef volatile LONG atomic_int; 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); } -static LONG atomic_load(atomic_int* ptr) { +static inline LONG atomic_load(atomic_int* ptr) { 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); } -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)); } +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 DWORD thread_ret_t;