summaryrefslogtreecommitdiff
path: root/ruby_atomic.h
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-26 02:45:53 (GMT)
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-26 02:45:53 (GMT)
commit0791c940ad9c4749e72accb91c7e22e684fde668 (patch)
treec82d6024bc65b84a2bc7c2fdbc3d6ec2ea181e0f /ruby_atomic.h
parent6295a023a5907af6f984aa5eeb9e64f99c5acf2b (diff)
* ruby_atomic.h: use __atomic builtin functions supported by GCC.
__sync family are legacy functions now and it is recommended that new code use the __atomic functions. http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html * configure.in: check existence of __atomic functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_atomic.h')
-rw-r--r--ruby_atomic.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/ruby_atomic.h b/ruby_atomic.h
index 7e16d28..091a608 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -3,6 +3,26 @@
#if 0
#elif defined HAVE_GCC_ATOMIC_BUILTINS
+typedef unsigned int rb_atomic_t;
+# define ATOMIC_SET(var, val) (void)__atomic_exchange_n(&(var), (val), __ATOMIC_SEQ_CST)
+# define ATOMIC_INC(var) __atomic_fetch_add(&(var), 1, __ATOMIC_SEQ_CST)
+# define ATOMIC_DEC(var) __atomic_fetch_sub(&(var), 1, __ATOMIC_SEQ_CST)
+# define ATOMIC_OR(var, val) __atomic_or_fetch(&(var), (val), __ATOMIC_SEQ_CST)
+# define ATOMIC_EXCHANGE(var, val) __atomic_exchange_n(&(var), (val), __ATOMIC_SEQ_CST)
+# define ATOMIC_CAS(var, oldval, newval) \
+({ __typeof__(__typeof__(var) *) ptr = &(var); /* expression var may have side effects */ \
+ __typeof__(oldval) oldvaldup = (oldval); /* oldval should not be modified */ \
+ __typeof__(var) tmp = *ptr; \
+ __atomic_compare_exchange_n(ptr, &oldvaldup, (newval), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
+ tmp; })
+
+# define ATOMIC_SIZE_ADD(var, val) __atomic_fetch_add(&(var), (val), __ATOMIC_SEQ_CST)
+# define ATOMIC_SIZE_SUB(var, val) __atomic_fetch_sub(&(var), (val), __ATOMIC_SEQ_CST)
+# define ATOMIC_SIZE_INC(var) __atomic_fetch_add(&(var), 1, __ATOMIC_SEQ_CST)
+# define ATOMIC_SIZE_DEC(var) __atomic_fetch_sub(&(var), 1, __ATOMIC_SEQ_CST)
+# define ATOMIC_SIZE_EXCHANGE(var, val) __atomic_exchange_n(&(var), (val), __ATOMIC_SEQ_CST)
+
+#elif defined HAVE_GCC_SYNC_BUILTINS
/* @shyouhei hack to support atomic operations in case of gcc. Gcc
* has its own pseudo-insns to support them. See info, or
* http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html */