Skip to content

Commit d3b6f83

Browse files
committed
Fix stdatomic case in rbimpl_atomic_u64_fetch_add
On some platoforms, 64bit atomic operations need the dedicated helper library.
1 parent ffa105c commit d3b6f83

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,7 @@ AS_IF([test "$GCC" = yes], [
17461746
[rb_cv_gcc_atomic_builtins=no])])
17471747
AS_IF([test "$rb_cv_gcc_atomic_builtins" = yes], [
17481748
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
1749+
AC_CHECK_LIB([atomic], [__atomic_fetch_add_8])
17491750
AC_CACHE_CHECK([for 64bit __atomic builtins], [rb_cv_gcc_atomic_builtins_64], [
17501751
AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdint.h>
17511752
uint64_t atomic_var;]],

ruby_atomic.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#define INTERNAL_ATOMIC_H
33

44
#include "ruby/atomic.h"
5+
#ifdef HAVE_STDATOMIC_H
6+
# include <stdatomic.h>
7+
#endif
58

69
#define RUBY_ATOMIC_VALUE_LOAD(x) rbimpl_atomic_value_load(&(x), RBIMPL_ATOMIC_SEQ_CST)
710

@@ -76,9 +79,9 @@ rbimpl_atomic_u64_fetch_add(volatile rbimpl_atomic_uint64_t *ptr, uint64_t val)
7679
return InterlockedExchangeAdd64((volatile LONG64 *)ptr, val);
7780
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
7881
return atomic_add_64_nv(ptr, val) - val;
82+
#elif defined(HAVE_STDATOMIC_H)
83+
return atomic_fetch_add_explicit((_Atomic uint64_t *)ptr, val, memory_order_seq_cst);
7984
#else
80-
// TODO: stdatomic
81-
8285
// Fallback using mutex for platforms without 64-bit atomics
8386
static rb_native_mutex_t lock = RB_NATIVE_MUTEX_INITIALIZER;
8487
rb_native_mutex_lock(&lock);

0 commit comments

Comments
 (0)