Skip to content

Commit 1d03a6b

Browse files
committed
Use stdatomic.h on recent macOS
1 parent e193872 commit 1d03a6b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ext/concurrent-ruby-ext/atomic_reference.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ VALUE ir_get_and_set(VALUE self, VALUE new_value) {
7878
}
7979

8080
VALUE ir_compare_and_set(volatile VALUE self, VALUE expect_value, VALUE new_value) {
81-
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
81+
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
82+
if (atomic_compare_exchange_strong_explicit((_Atomic uintptr_t *)&DATA_PTR(self), &expect_value, new_value, memory_order_seq_cst, memory_order_seq_cst)) {
83+
return Qtrue;
84+
}
85+
#elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
8286
if (OSAtomicCompareAndSwap64(expect_value, new_value, &DATA_PTR(self))) {
8387
return Qtrue;
8488
}

ext/concurrent-ruby-ext/atomic_reference.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <atomic.h>
66
#endif
77

8+
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
9+
#include <stdatomic.h>
10+
#endif
811
#ifdef HAVE_LIBKERN_OSATOMIC_H
912
#include <libkern/OSAtomic.h>
1013
#endif

0 commit comments

Comments
 (0)