diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-11 14:27:08 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-11 14:27:08 +0000 |
commit | 9d4e471cf974d99ab01fc243b5419c6711888540 (patch) | |
tree | 531f8251fc433d165eb8a946cb9d6b6fad2aa7c0 /signal.c | |
parent | 8df20d6b169ed6b8e76927b5ce5db9acb0208a8b (diff) |
* vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT,
RUBY_VM_SET_FINALIZER_INTERRUPT): use atomic ops for preventing
interrupt_flag bit lost.
* thread.c (rb_threadptr_execute_interrupts_rec): ditto.
* vm_core.h (typedef struct rb_thread_struct): change type of
interrupt_flag to rb_atomic_t.
* atomic.h: move atomic ops definition from signal.c.
* signal.c: remove atomic ops definition.
* common.mk (gc, signal, thread, cont): add to dependency to atomic.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r-- | signal.c | 34 |
1 files changed, 8 insertions, 26 deletions
@@ -16,33 +16,15 @@ #include <signal.h> #include <stdio.h> #include <errno.h> +#include "atomic.h" -#ifdef _WIN32 -typedef LONG rb_atomic_t; - -# define ATOMIC_TEST(var) InterlockedExchange(&(var), 0) -# define ATOMIC_SET(var, val) InterlockedExchange(&(var), (val)) -# define ATOMIC_INC(var) InterlockedIncrement(&(var)) -# define ATOMIC_DEC(var) InterlockedDecrement(&(var)) - -#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_TEST(var) __sync_lock_test_and_set(&(var), 0) -# define ATOMIC_SET(var, val) __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) - -#else -typedef int rb_atomic_t; - -# define ATOMIC_TEST(var) ((var) ? ((var) = 0, 1) : 0) -# define ATOMIC_SET(var, val) ((var) = (val)) -# define ATOMIC_INC(var) (++(var)) -# define ATOMIC_DEC(var) (--(var)) +#if !defined(_WIN32) && !defined(HAVE_GCC_ATOMIC_BUILTINS) +rb_atomic_t ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val) +{ + rb_atomic_t old = *ptr; + *ptr = val; + return old; +} #endif #if defined(__BEOS__) || defined(__HAIKU__) |