diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-11-25 11:59:50 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu.nakada@gmail.com> | 2025-11-25 13:47:45 +0900 |
| commit | bbf4bde75e4c8d2eacc40fc5e544ee73b20cf586 (patch) | |
| tree | 8dc2b812d775ffa312a92114e3ff5ad14611ddcc | |
| parent | f8ee06901cfec2ebb7340087f039b103e8ab51b3 (diff) | |
Reapply "Fix stdatomic case in `rbimpl_atomic_u64_fetch_add`"
This reverts commit 8a68dc7bdd3d1c97677a6633a4f2b5e524c492ae.
| -rw-r--r-- | configure.ac | 1 | ||||
| -rw-r--r-- | ruby_atomic.h | 7 |
2 files changed, 6 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index 339ee3b2f2..1e406ec56c 100644 --- a/configure.ac +++ b/configure.ac @@ -1746,6 +1746,7 @@ AS_IF([test "$GCC" = yes], [ [rb_cv_gcc_atomic_builtins=no])]) AS_IF([test "$rb_cv_gcc_atomic_builtins" = yes], [ AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS) + AC_CHECK_LIB([atomic], [__atomic_fetch_add_8]) AC_CACHE_CHECK([for 64bit __atomic builtins], [rb_cv_gcc_atomic_builtins_64], [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdint.h> uint64_t atomic_var;]], diff --git a/ruby_atomic.h b/ruby_atomic.h index c194f7ec3b..3a541d9208 100644 --- a/ruby_atomic.h +++ b/ruby_atomic.h @@ -2,6 +2,9 @@ #define INTERNAL_ATOMIC_H #include "ruby/atomic.h" +#ifdef HAVE_STDATOMIC_H +# include <stdatomic.h> +#endif #define RUBY_ATOMIC_VALUE_LOAD(x) rbimpl_atomic_value_load(&(x), RBIMPL_ATOMIC_SEQ_CST) @@ -76,9 +79,9 @@ rbimpl_atomic_u64_fetch_add(volatile rbimpl_atomic_uint64_t *ptr, uint64_t val) return InterlockedExchangeAdd64((volatile LONG64 *)ptr, val); #elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx)) return atomic_add_64_nv(ptr, val) - val; +#elif defined(HAVE_STDATOMIC_H) + return atomic_fetch_add_explicit((_Atomic uint64_t *)ptr, val, memory_order_seq_cst); #else - // TODO: stdatomic - // Fallback using mutex for platforms without 64-bit atomics static rb_native_mutex_t lock = RB_NATIVE_MUTEX_INITIALIZER; rb_native_mutex_lock(&lock); |
