Skip to content

Commit d11c9c7

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 7776634 commit d11c9c7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/BlocksRuntime/runtime.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
//
99

1010
#include "Block_private.h"
11+
#include <stdatomic.h>
12+
#include <stdint.h>
1113
#include <stdio.h>
1214
#include <stdlib.h>
1315
#include <string.h>
14-
#include <stdint.h>
1516
#if HAVE_OBJC
1617
#define __USE_GNU
1718
#include <dlfcn.h>
@@ -32,9 +33,10 @@
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, false, __ATOMIC_RELAXED, \
39+
__ATOMIC_RELAXED)
3840
#else
3941
#define _CRT_SECURE_NO_WARNINGS 1
4042
#include <Windows.h>

0 commit comments

Comments
 (0)