浏览代码

Use InterlockedCompareExchange on windows

ithewei 3 年之前
父节点
当前提交
0f527ae810
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      base/hatomic.h

+ 6 - 0
base/hatomic.h

@@ -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