summaryrefslogtreecommitdiff
path: root/ruby_atomic.h
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-27 14:57:33 (GMT)
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-27 14:57:33 (GMT)
commitb983511292f8caa10ce4e7a8ea5387efe3862b52 (patch)
treef73e50138128c6d5618490e4bd5b5eaa05dd9200 /ruby_atomic.h
parentda666770616728875f9d3b79878c50f8cd0a84fa (diff)
* ruby_atomic.h: define ATOMIC_SIZE_CAS() with
__atomic_compare_exchange_n() and refactoring. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_atomic.h')
-rw-r--r--ruby_atomic.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/ruby_atomic.h b/ruby_atomic.h
index 091a608..33478d6 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -10,17 +10,19 @@ typedef unsigned int rb_atomic_t;
# 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; })
+({ __typeof__(oldval) oldvaldup = (oldval); /* oldval should not be modified */ \
+ __atomic_compare_exchange_n(&(var), &oldvaldup, (newval), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
+ oldvaldup; })
# 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)
+# define ATOMIC_SIZE_CAS(var, oldval, newval) \
+({ size_t oldvaldup = (oldval); \
+ __atomic_compare_exchange_n(&(var), &oldvaldup, (newval), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
+ oldvaldup; })
#elif defined HAVE_GCC_SYNC_BUILTINS
/* @shyouhei hack to support atomic operations in case of gcc. Gcc