Skip to content

Commit

Permalink
Use proper atomics and ref counting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AreaZR committed Dec 24, 2023
1 parent ee39300 commit 2da1073
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/BlocksRuntime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdatomic.h>
#if HAVE_OBJC
#define __USE_GNU
#include <dlfcn.h>
Expand All @@ -32,9 +33,9 @@
#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, true, memory_order_acq_rel, memory_order_relaxed)
#else
#define _CRT_SECURE_NO_WARNINGS 1
#include <Windows.h>
Expand Down

0 comments on commit 2da1073

Please sign in to comment.