From d11c9c7fdd4a66b6e182eee135f46ca333630e67 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:13:38 -0500 Subject: [PATCH] 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. --- src/BlocksRuntime/runtime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/BlocksRuntime/runtime.c b/src/BlocksRuntime/runtime.c index 4b7d4bfa2..0a711b310 100644 --- a/src/BlocksRuntime/runtime.c +++ b/src/BlocksRuntime/runtime.c @@ -8,10 +8,11 @@ // #include "Block_private.h" +#include +#include #include #include #include -#include #if HAVE_OBJC #define __USE_GNU #include @@ -32,9 +33,10 @@ #define __has_builtin(builtin) 0 #endif -#if __has_builtin(__sync_bool_compare_and_swap) +#if __has_builtin(__atomic_compare_exchange_n) #define OSAtomicCompareAndSwapInt(_Old, _New, _Ptr) \ - __sync_bool_compare_and_swap(_Ptr, _Old, _New) + __atomic_compare_exchange_n(_Ptr, &_Old, _New, false, __ATOMIC_RELAXED, \ + __ATOMIC_RELAXED) #else #define _CRT_SECURE_NO_WARNINGS 1 #include