Skip to content

Commit 2da1073

Browse files
committed
Use proper atomics and ref counting
Prefer __atomic_compare_exchange_n over __sync_bool_compare_and_swap. I chose weak because we are looping and reading the value of old_value constantly anyway, so it would be better to have it weak. Otherwise, it is equivalent to what it was before.
1 parent ee39300 commit 2da1073

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/BlocksRuntime/runtime.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414
#include <stdint.h>
15+
#include <stdatomic.h>
1516
#if HAVE_OBJC
1617
#define __USE_GNU
1718
#include <dlfcn.h>
@@ -32,9 +33,9 @@
3233
#define __has_builtin(builtin) 0
3334
#endif
3435

35-
#if __has_builtin(__sync_bool_compare_and_swap)
36+
#if __has_builtin(__atomic_compare_exchange_n)
3637
#define OSAtomicCompareAndSwapInt(_Old, _New, _Ptr) \
37-
__sync_bool_compare_and_swap(_Ptr, _Old, _New)
38+
__atomic_compare_exchange_n(_Ptr, &_Old, _New, true, memory_order_acq_rel, memory_order_relaxed)
3839
#else
3940
#define _CRT_SECURE_NO_WARNINGS 1
4041
#include <Windows.h>

0 commit comments

Comments
 (0)