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.
This commit is contained in:
John Hawthorn 2025-07-28 23:24:11 -07:00
parent 77d29ef73c
commit cb360b0b4b
2 changed files with 10 additions and 1 deletions

View file

@ -1156,6 +1156,15 @@ rbimpl_atomic_ptr_load(void **ptr, int memory_order)
#endif #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_ARTIFICIAL()
RBIMPL_ATTR_NOALIAS() RBIMPL_ATTR_NOALIAS()
RBIMPL_ATTR_NONNULL((1)) RBIMPL_ATTR_NONNULL((1))

View file

@ -3,7 +3,7 @@
#include "ruby/atomic.h" #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 */ /* shim macros only */
#define ATOMIC_ADD(var, val) RUBY_ATOMIC_ADD(var, val) #define ATOMIC_ADD(var, val) RUBY_ATOMIC_ADD(var, val)