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
AZero13 committed Apr 18, 2024
1 parent 7776634 commit d11c9c7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/BlocksRuntime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
//

#include "Block_private.h"
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#if HAVE_OBJC
#define __USE_GNU
#include <dlfcn.h>
Expand All @@ -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 <Windows.h>
Expand Down

0 comments on commit d11c9c7

Please sign in to comment.