Use InterlockedCompareExchange on windows
@@ -46,6 +46,12 @@ typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
#ifdef _WIN32
+#define ATOMIC_FLAG_TEST_AND_SET atomic_flag_test_and_set
+static inline bool atomic_flag_test_and_set(atomic_flag* p) {
+ // return InterlockedIncrement((LONG*)&p->_Value, 1);
+ return InterlockedCompareExchange((LONG*)&p->_Value, 1, 0);
+}
+
#define ATOMIC_ADD InterlockedAdd
#define ATOMIC_SUB(p, n) InterlockedAdd(p, -n)
#define ATOMIC_INC InterlockedIncrement
