summaryrefslogtreecommitdiff
path: root/ruby_atomic.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-05 01:48:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-05 01:48:10 +0000
commitfb29aefc7abe3fe1b2c7794035a73f9ba50e8364 (patch)
tree63f16c3adcf4dbb060558f3f98aa5a15f3bcec4b /ruby_atomic.h
parentb8434daf6b59aef144c76a4a0842550f64a2a56e (diff)
downloadbundler-fb29aefc7abe3fe1b2c7794035a73f9ba50e8364.tar.gz
ruby_atomic.h: ATOMIC_PTR_EXCHANGE
* ruby_atomic.h (ATOMIC_PTR_EXCHANGE): atomic exchange function for a generic pointer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_atomic.h')
-rw-r--r--ruby_atomic.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/ruby_atomic.h b/ruby_atomic.h
index 8e574153af..69efbdc4c4 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -17,6 +17,8 @@ typedef unsigned int rb_atomic_t;
# 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_PTR_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
@@ -33,6 +35,8 @@ typedef unsigned int rb_atomic_t; /* Anything OK */
# define ATOMIC_SIZE_ADD(var, val) __sync_fetch_and_add(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) __sync_fetch_and_sub(&(var), (val))
+# define ATOMIC_PTR_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
+
#elif defined _WIN32
#if defined _MSC_VER && _MSC_VER > 1200
#pragma intrinsic(_InterlockedOr)
@@ -152,4 +156,10 @@ atomic_size_exchange(size_t *ptr, size_t val)
# define ATOMIC_SIZE_CAS(var, oldval, val) ATOMIC_CAS(var, oldval, val)
#endif
+#ifndef ATOMIC_PTR_EXCHANGE
+# if SIZEOF_VOIDP == SIZEOF_SIZE_T
+# define ATOMIC_PTR_EXCHANGE(var, val) (void *)ATOMIC_SIZE_EXCHANGE(*(size_t *)&(var), (size_t)(val))
+# endif
+#endif
+
#endif /* RUBY_ATOMIC_H */