From cb360b0b4b2e53f2335f77f477df54337fc4d87e Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 28 Jul 2025 23:24:11 -0700 Subject: [PATCH] Implement rbimpl_atomic_value_load This only adds the rbimpl_ version to include/ruby/atomic.h so that it is not a new public interface. We were already using RUBY_ATOMIC_VALUE_LOAD in a few locations. This will allow us to use other memory orders internally when desired. --- include/ruby/atomic.h | 9 +++++++++ ruby_atomic.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/ruby/atomic.h b/include/ruby/atomic.h index 89e1111e4c..650891ab9c 100644 --- a/include/ruby/atomic.h +++ b/include/ruby/atomic.h @@ -1156,6 +1156,15 @@ rbimpl_atomic_ptr_load(void **ptr, int memory_order) #endif } +RBIMPL_ATTR_ARTIFICIAL() +RBIMPL_ATTR_NOALIAS() +RBIMPL_ATTR_NONNULL((1)) +static inline VALUE +rbimpl_atomic_value_load(volatile VALUE *ptr, int memory_order) +{ + return RBIMPL_CAST((VALUE)rbimpl_atomic_ptr_load((void **)ptr, memory_order)); +} + RBIMPL_ATTR_ARTIFICIAL() RBIMPL_ATTR_NOALIAS() RBIMPL_ATTR_NONNULL((1)) diff --git a/ruby_atomic.h b/ruby_atomic.h index 2923275636..ad53356f06 100644 --- a/ruby_atomic.h +++ b/ruby_atomic.h @@ -3,7 +3,7 @@ #include "ruby/atomic.h" -#define RUBY_ATOMIC_VALUE_LOAD(x) (VALUE)(RUBY_ATOMIC_PTR_LOAD(x)) +#define RUBY_ATOMIC_VALUE_LOAD(x) rbimpl_atomic_value_load(&(x), RBIMPL_ATOMIC_SEQ_CST) /* shim macros only */ #define ATOMIC_ADD(var, val) RUBY_ATOMIC_ADD(var, val)