summaryrefslogtreecommitdiff
path: root/ruby_atomic.h
diff options
context:
space:
mode:
authorJohn Hawthorn <[email protected]>2025-05-14 18:28:53 -0700
committerJohn Hawthorn <[email protected]>2025-05-20 09:56:31 -0700
commit05e0e7223acbc9ab223dd8f4b342d5eb6d3ae8c7 (patch)
tree15c3ed684845a6828e0935e87c6d90c2a3c46aec /ruby_atomic.h
parentcd15cc250fa7dc6482833327728eeff641d2e41d (diff)
Use atomic load to read interrupt mask
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13357
Diffstat (limited to 'ruby_atomic.h')
-rw-r--r--ruby_atomic.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/ruby_atomic.h b/ruby_atomic.h
index 57d341082d..085c307ac6 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -1,3 +1,6 @@
+#ifndef INTERNAL_ATOMIC_H
+#define INTERNAL_ATOMIC_H
+
#include "ruby/atomic.h"
/* shim macros only */
@@ -21,3 +24,16 @@
#define ATOMIC_SUB(var, val) RUBY_ATOMIC_SUB(var, val)
#define ATOMIC_VALUE_CAS(var, oldval, val) RUBY_ATOMIC_VALUE_CAS(var, oldval, val)
#define ATOMIC_VALUE_EXCHANGE(var, val) RUBY_ATOMIC_VALUE_EXCHANGE(var, val)
+
+static inline rb_atomic_t
+rbimpl_atomic_load_relaxed(rb_atomic_t *ptr)
+{
+#if defined(HAVE_GCC_ATOMIC_BUILTINS)
+ return __atomic_load_n(ptr, __ATOMIC_RELAXED);
+#else
+ return *ptr;
+#endif
+}
+#define ATOMIC_LOAD_RELAXED(var) rbimpl_atomic_load_relaxed(&(var))
+
+#endif