[前][次][番号順一覧][スレッド一覧]

ruby-changes:31803

From: glass <ko1@a...>
Date: Wed, 27 Nov 2013 23:57:39 +0900 (JST)
Subject: [ruby-changes:31803] glass:r43882 (trunk): * ruby_atomic.h: define ATOMIC_SIZE_CAS() with

glass	2013-11-27 23:57:33 +0900 (Wed, 27 Nov 2013)

  New Revision: 43882

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43882

  Log:
    * ruby_atomic.h: define ATOMIC_SIZE_CAS() with
      __atomic_compare_exchange_n() and refactoring.

  Modified files:
    trunk/ChangeLog
    trunk/ruby_atomic.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43881)
+++ ChangeLog	(revision 43882)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 27 23:55:50 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* ruby_atomic.h: define ATOMIC_SIZE_CAS() with
+	  __atomic_compare_exchange_n() and refactoring.
+
 Tue Nov 27 21:43:00 2013  Akira Matsuda  <ronnie@d...>
 
 	* lib/irb/notifier.rb:  [Doc] Fix typo
Index: ruby_atomic.h
===================================================================
--- ruby_atomic.h	(revision 43881)
+++ ruby_atomic.h	(revision 43882)
@@ -10,17 +10,19 @@ typedef unsigned int rb_atomic_t; https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L10
 # 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]