mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
atomic.h: prefer GCC atomic builtins
* atomic.h: prefer GCC atomic builtins than Windows APIs, if possible, since they are generic. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
61a67bc720
commit
ac64f196f8
2 changed files with 25 additions and 19 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jul 25 17:17:05 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* atomic.h: prefer GCC atomic builtins than Windows APIs, if possible,
|
||||
since they are generic.
|
||||
|
||||
Wed Jul 25 11:16:57 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/net/.document: Removed. All files in net/ should be included in
|
||||
|
|
39
atomic.h
39
atomic.h
|
@ -1,7 +1,26 @@
|
|||
#ifndef RUBY_ATOMIC_H
|
||||
#define RUBY_ATOMIC_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#if 0
|
||||
#elif defined HAVE_GCC_ATOMIC_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 */
|
||||
|
||||
typedef unsigned int rb_atomic_t; /* Anything OK */
|
||||
# define ATOMIC_SET(var, val) (void)__sync_lock_test_and_set(&(var), (val))
|
||||
# define ATOMIC_INC(var) __sync_fetch_and_add(&(var), 1)
|
||||
# define ATOMIC_DEC(var) __sync_fetch_and_sub(&(var), 1)
|
||||
# define ATOMIC_OR(var, val) __sync_or_and_fetch(&(var), (val))
|
||||
# define ATOMIC_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
|
||||
|
||||
# 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_SIZE_INC(var) __sync_fetch_and_add(&(var), 1)
|
||||
# define ATOMIC_SIZE_DEC(var) __sync_fetch_and_sub(&(var), 1)
|
||||
# define ATOMIC_SIZE_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
|
||||
|
||||
#elif defined _WIN32
|
||||
#if defined _MSC_VER && _MSC_VER > 1200
|
||||
#pragma intrinsic(_InterlockedOr)
|
||||
#endif
|
||||
|
@ -44,24 +63,6 @@ rb_w32_atomic_or(volatile rb_atomic_t *var, rb_atomic_t val)
|
|||
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange((LONG *)&(var), (val))
|
||||
# endif
|
||||
|
||||
#elif defined HAVE_GCC_ATOMIC_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 */
|
||||
|
||||
typedef unsigned int rb_atomic_t; /* Anything OK */
|
||||
# define ATOMIC_SET(var, val) (void)__sync_lock_test_and_set(&(var), (val))
|
||||
# define ATOMIC_INC(var) __sync_fetch_and_add(&(var), 1)
|
||||
# define ATOMIC_DEC(var) __sync_fetch_and_sub(&(var), 1)
|
||||
# define ATOMIC_OR(var, val) __sync_or_and_fetch(&(var), (val))
|
||||
# define ATOMIC_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
|
||||
|
||||
# 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_SIZE_INC(var) __sync_fetch_and_add(&(var), 1)
|
||||
# define ATOMIC_SIZE_DEC(var) __sync_fetch_and_sub(&(var), 1)
|
||||
# define ATOMIC_SIZE_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
|
||||
|
||||
#elif defined(__sun)
|
||||
#include <atomic.h>
|
||||
typedef unsigned int rb_atomic_t;
|
||||
|
|
Loading…
Reference in a new issue