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

ruby-changes:31772

From: glass <ko1@a...>
Date: Tue, 26 Nov 2013 11:45:59 +0900 (JST)
Subject: [ruby-changes:31772] glass:r43851 (trunk): * ruby_atomic.h: use __atomic builtin functions supported by GCC.

glass	2013-11-26 11:45:53 +0900 (Tue, 26 Nov 2013)

  New Revision: 43851

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

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/ruby_atomic.h
Index: configure.in
===================================================================
--- configure.in	(revision 43850)
+++ configure.in	(revision 43851)
@@ -1480,13 +1480,14 @@ if test "$GCC" = yes; then https://github.com/ruby/ruby/blob/trunk/configure.in#L1480
 	AC_DEFINE_UNQUOTED([RUBY_ALIAS_FUNCTION_VOID(prot, name, args)],
 			   [RUBY_ALIAS_FUNCTION_TYPE(void, prot, name, args)])
     fi
-    AC_CACHE_CHECK([for atomic builtins], [rb_cv_gcc_atomic_builtins], [
+
+    AC_CACHE_CHECK([for __atomic builtins], [rb_cv_gcc_atomic_builtins], [
 	AC_TRY_LINK([unsigned char atomic_var;],
 		    [
-			__sync_lock_test_and_set(&atomic_var, 0);
-			__sync_lock_test_and_set(&atomic_var, 1);
-			__sync_fetch_and_add(&atomic_var, 1);
-			__sync_fetch_and_sub(&atomic_var, 1);
+			__atomic_exchange_n(&atomic_var, 0, __ATOMIC_SEQ_CST);
+			__atomic_exchange_n(&atomic_var, 1, __ATOMIC_SEQ_CST);
+			__atomic_fetch_add(&atomic_var, 1, __ATOMIC_SEQ_CST);
+			__atomic_fetch_sub(&atomic_var, 1, __ATOMIC_SEQ_CST);
 		    ],
 		    [rb_cv_gcc_atomic_builtins=yes],
 		    [rb_cv_gcc_atomic_builtins=no])])
@@ -1494,6 +1495,20 @@ if test "$GCC" = yes; then https://github.com/ruby/ruby/blob/trunk/configure.in#L1495
 	AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
     fi
 
+    AC_CACHE_CHECK([for __sync builtins], [rb_cv_gcc_sync_builtins], [
+	AC_TRY_LINK([unsigned char atomic_var;],
+		    [
+			__sync_lock_test_and_set(&atomic_var, 0);
+			__sync_lock_test_and_set(&atomic_var, 1);
+			__sync_fetch_and_add(&atomic_var, 1);
+			__sync_fetch_and_sub(&atomic_var, 1);
+		    ],
+		    [rb_cv_gcc_sync_builtins=yes],
+		    [rb_cv_gcc_sync_builtins=no])])
+    if test "$rb_cv_gcc_sync_builtins" = yes; then
+	AC_DEFINE(HAVE_GCC_SYNC_BUILTINS)
+    fi
+
     AC_CACHE_CHECK(for __builtin_unreachable, rb_cv_func___builtin_unreachable,
     [RUBY_WERROR_FLAG(
     [AC_TRY_LINK([@%:@include <stdlib.h>],
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43850)
+++ ChangeLog	(revision 43851)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Nov 26 11:43:19 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* 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.
+
 Tue Nov 26 10:57:49 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/bigdecimal/bigdecimal.gemspec: revert Gem::Specification#date
Index: ruby_atomic.h
===================================================================
--- ruby_atomic.h	(revision 43850)
+++ ruby_atomic.h	(revision 43851)
@@ -3,6 +3,26 @@ https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L3
 
 #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 */

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

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