1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
glass 2013-11-26 02:45:53 +00:00
parent 6295a023a5
commit 0791c940ad
3 changed files with 49 additions and 5 deletions

View file

@ -1,3 +1,12 @@
Tue Nov 26 11:43:19 2013 Masaki Matsushita <glass.saga@gmail.com>
* 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@ruby-lang.org>
* ext/bigdecimal/bigdecimal.gemspec: revert Gem::Specification#date

View file

@ -1480,7 +1480,22 @@ if test "$GCC" = yes; then
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;],
[
__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])])
if test "$rb_cv_gcc_atomic_builtins" = yes; then
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);
@ -1488,10 +1503,10 @@ if test "$GCC" = yes; then
__sync_fetch_and_add(&atomic_var, 1);
__sync_fetch_and_sub(&atomic_var, 1);
],
[rb_cv_gcc_atomic_builtins=yes],
[rb_cv_gcc_atomic_builtins=no])])
if test "$rb_cv_gcc_atomic_builtins" = yes; then
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
[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,

View file

@ -3,6 +3,26 @@
#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 */