Skip to content

Commit

Permalink
* gc.c, atomic.h (ATOMIC_SIZE_*): moved from gc.c to atomic.h [ruby-d…
Browse files Browse the repository at this point in the history
…ev:45909]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ngoto committed Jul 4, 2012
1 parent 31f3a2e commit 87c25d8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Wed Jul 4 21:41:44 2012 Naohisa Goto <[email protected]>

* gc.c, atomic.h (ATOMIC_SIZE_*): moved from gc.c to atomic.h
[ruby-dev:45909]

Wed Jul 4 19:13:15 2012 Masaki Suketa <[email protected]>

* test/win32ole/test_win32ole.rb (test_s_codepage_changed):
Expand Down
47 changes: 47 additions & 0 deletions atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ rb_w32_atomic_or(volatile rb_atomic_t *var, rb_atomic_t val)
#endif
# define ATOMIC_EXCHANGE(var, val) InterlockedExchange(&(var), (val))

# ifdef _M_AMD64
# define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd64(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd64(&(var), -(val))
# define ATOMIC_SIZE_INC(var) InterlockedIncrement64(&(var))
# define ATOMIC_SIZE_DEC(var) InterlockedDecrement64(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange64(&(var), (val))
# else
# define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd(&(var), -(val))
# define ATOMIC_SIZE_INC(var) InterlockedIncrement(&(var))
# define ATOMIC_SIZE_DEC(var) InterlockedDecrement(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange(&(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
Expand All @@ -42,6 +56,12 @@ typedef unsigned int rb_atomic_t; /* Anything OK */
# 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;
Expand All @@ -52,6 +72,20 @@ typedef unsigned int rb_atomic_t;
# define ATOMIC_OR(var, val) atomic_or_uint(&(var), (val))
# define ATOMIC_EXCHANGE(var, val) atomic_swap_uint(&(var), (val))

# if SIZEOF_SIZE_T == SIZEOF_LONG
# define ATOMIC_SIZE_ADD(var, val) atomic_add_long(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) atomic_add_long(&(var), -(val))
# define ATOMIC_SIZE_INC(var) atomic_inc_ulong(&(var))
# define ATOMIC_SIZE_DEC(var) atomic_dec_ulong(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_swap_ulong(&(var), (val))
# else
# define ATOMIC_SIZE_ADD(var, val) atomic_add_int(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) atomic_add_int(&(var), -(val))
# define ATOMIC_SIZE_INC(var) atomic_inc_uint(&(var))
# define ATOMIC_SIZE_DEC(var) atomic_dec_uint(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_swap_uint(&(var), (val))
# endif

#else
typedef int rb_atomic_t;
#define NEED_RUBY_ATOMIC_EXCHANGE
Expand All @@ -62,6 +96,19 @@ extern rb_atomic_t ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val);
# define ATOMIC_DEC(var) ((var)--)
# define ATOMIC_OR(var, val) ((var) |= (val))
# define ATOMIC_EXCHANGE(var, val) ruby_atomic_exchange(&(var), (val))

# define ATOMIC_SIZE_ADD(var, val) (void)((var) += (val))
# define ATOMIC_SIZE_SUB(var, val) (void)((var) -= (val))
# define ATOMIC_SIZE_INC(var) ((var)++)
# define ATOMIC_SIZE_DEC(var) ((var)--)
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_size_exchange(&(var), (val))
static inline size_t
atomic_size_exchange(size_t *ptr, size_t val)
{
size_t old = *ptr;
*ptr = val;
return old;
}
#endif

#endif /* RUBY_ATOMIC_H */
51 changes: 1 addition & 50 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "internal.h"
#include "gc.h"
#include "constant.h"
#include "atomic.h"
#include <stdio.h>
#include <setjmp.h>
#include <sys/types.h>
Expand Down Expand Up @@ -60,56 +61,6 @@
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) /* empty */
#endif

#if defined _WIN32
# ifdef _M_AMD64
# define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd64(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd64(&(var), -(val))
# define ATOMIC_SIZE_INC(var) InterlockedIncrement64(&(var))
# define ATOMIC_SIZE_DEC(var) InterlockedDecrement64(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange64(&(var), (val))
# else
# define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd(&(var), -(val))
# define ATOMIC_SIZE_INC(var) InterlockedIncrement(&(var))
# define ATOMIC_SIZE_DEC(var) InterlockedDecrement(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange(&(var), (val))
# endif
#elif defined HAVE_GCC_ATOMIC_BUILTINS
# 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>
# if SIZEOF_SIZE_T == SIZEOF_LONG
# define ATOMIC_SIZE_ADD(var, val) atomic_add_long(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) atomic_add_long(&(var), -(val))
# define ATOMIC_SIZE_INC(var) atomic_inc_ulong(&(var))
# define ATOMIC_SIZE_DEC(var) atomic_dec_ulong(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_swap_ulong(&(var), (val))
# else
# define ATOMIC_SIZE_ADD(var, val) atomic_add_int(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) atomic_add_int(&(var), -(val))
# define ATOMIC_SIZE_INC(var) atomic_inc_uint(&(var))
# define ATOMIC_SIZE_DEC(var) atomic_dec_uint(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_swap_uint(&(var), (val))
# endif
#else
# define ATOMIC_SIZE_ADD(var, val) (void)((var) += (val))
# define ATOMIC_SIZE_SUB(var, val) (void)((var) -= (val))
# define ATOMIC_SIZE_INC(var) ((var)++)
# define ATOMIC_SIZE_DEC(var) ((var)--)
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_size_exchange(&(var), (val))
static inline size_t
atomic_size_exchange(size_t *ptr, size_t val)
{
size_t old = *ptr;
*ptr = val;
return old;
}
#endif

#define rb_setjmp(env) RUBY_SETJMP(env)
#define rb_jmp_buf rb_jmpbuf_t

Expand Down

0 comments on commit 87c25d8

Please sign in to comment.