Skip to content

Commit eacd77a

Browse files
nobueregon
authored andcommitted
Use stdatomic.h on recent macOS
1 parent e193872 commit eacd77a

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
VALUEir_compare_and_set(volatileVALUEself, VALUEexpect_value, VALUEnew_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+
returnQtrue;
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
returnQtrue;
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
#ifdefHAVE_LIBKERN_OSATOMIC_H
912
#include<libkern/OSAtomic.h>
1013
#endif

0 commit comments

Comments
(0)