Reapply "Fix stdatomic case in rbimpl_atomic_u64_fetch_add"

This reverts commit 8a68dc7bdd3d1c97677a6633a4f2b5e524c492ae.
This commit is contained in:
Nobuyoshi Nakada 2025-11-25 11:59:50 +09:00 committed by Nobuyoshi Nakada
parent f8ee06901c
commit bbf4bde75e
Notes: git 2025-12-18 19:57:38 +00:00
2 changed files with 6 additions and 2 deletions

View File

@ -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;]],

View File

@ -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);