ruby-changes:31917
From: nobu <ko1@a...>
Date: Thu, 5 Dec 2013 10:48:22 +0900 (JST)
Subject: [ruby-changes:31917] nobu:r43996 (trunk): ruby_atomic.h: ATOMIC_PTR_EXCHANGE
nobu 2013-12-05 10:48:10 +0900 (Thu, 05 Dec 2013) New Revision: 43996 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43996 Log: ruby_atomic.h: ATOMIC_PTR_EXCHANGE * ruby_atomic.h (ATOMIC_PTR_EXCHANGE): atomic exchange function for a generic pointer. Modified files: trunk/ChangeLog trunk/ruby_atomic.h Index: ChangeLog =================================================================== --- ChangeLog (revision 43995) +++ ChangeLog (revision 43996) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Dec 5 10:47:56 2013 Nobuyoshi Nakada <nobu@r...> + + * ruby_atomic.h (ATOMIC_PTR_EXCHANGE): atomic exchange function for + a generic pointer. + Thu Dec 5 10:47:09 2013 Nobuyoshi Nakada <nobu@r...> * gc.c (finalize_deferred): flush all deferred finalizers while other Index: ruby_atomic.h =================================================================== --- ruby_atomic.h (revision 43995) +++ ruby_atomic.h (revision 43996) @@ -17,6 +17,8 @@ typedef unsigned int rb_atomic_t; https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L17 # 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; /* Any https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L35 # 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 https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L156 # 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 */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/