diff --git a/ChangeLog b/ChangeLog index 3398eb29c4..6d1c58f244 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Nov 26 21:16:04 2012 KOSAKI Motohiro + + * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT) + (RUBY_VM_SET_FINALIZER_INTERRUPT, RUBY_VM_SET_TRAP_INTERRUPT) + (RUBY_VM_INTERRUPTED): use enum symbol instead of immediate value. + * thread.c (thread_join_m, rb_threadptr_execute_interrupts): ditto. + * signal.c (signal_exec): ditto. + Mon Nov 26 20:23:20 2012 KOSAKI Motohiro * thread.c (thread_join_m): use th->interrupt_mask instead of diff --git a/signal.c b/signal.c index 7bf0404f92..ba19e6d0af 100644 --- a/signal.c +++ b/signal.c @@ -627,7 +627,7 @@ signal_exec(VALUE cmd, int safe, int sig) volatile unsigned long old_interrupt_mask = cur_th->interrupt_mask; int state; - cur_th->interrupt_mask |= 0x08; + cur_th->interrupt_mask |= TRAP_INTERRUPT_MASK; TH_PUSH_TAG(cur_th); if ((state = EXEC_TAG()) == 0) { VALUE signum = INT2NUM(sig); diff --git a/thread.c b/thread.c index 3264548480..0ff0794785 100644 --- a/thread.c +++ b/thread.c @@ -810,7 +810,8 @@ thread_join_m(int argc, VALUE *argv, VALUE self) double delay = DELAY_INFTY; VALUE limit; - if (cur_th->interrupt_mask & 0x08) { + /* When running trap handler */ + if (cur_th->interrupt_mask & TRAP_INTERRUPT_MASK) { rb_raise(rb_eThreadError, "can't be called from trap context"); } @@ -1747,10 +1748,10 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing) if (!interrupt) return; - timer_interrupt = interrupt & 0x01; - async_errinfo_interrupt = interrupt & 0x02; - finalizer_interrupt = interrupt & 0x04; - trap_interrupt = interrupt & 0x08; + timer_interrupt = interrupt & TIMER_INTERRUPT_MASK; + async_errinfo_interrupt = interrupt & ASYNC_ERRINFO_INTERRUPT_MASK; + finalizer_interrupt = interrupt & FINALIZER_INTERRUPT_MASK; + trap_interrupt = interrupt & TRAP_INTERRUPT_MASK; th->status = THREAD_RUNNABLE; diff --git a/vm_core.h b/vm_core.h index 8a9c4e63e4..f9b6181f54 100644 --- a/vm_core.h +++ b/vm_core.h @@ -855,11 +855,18 @@ GET_THREAD(void) #error "unsupported thread model" #endif -#define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, 0x01) -#define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, 0x02) -#define RUBY_VM_SET_FINALIZER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, 0x04) -#define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, 0x08) -#define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & 0x0A & ~(th)->interrupt_mask) +enum { + TIMER_INTERRUPT_MASK = 0x01, + ASYNC_ERRINFO_INTERRUPT_MASK = 0x02, + FINALIZER_INTERRUPT_MASK = 0x04, + TRAP_INTERRUPT_MASK = 0x08 +}; + +#define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TIMER_INTERRUPT_MASK) +#define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, ASYNC_ERRINFO_INTERRUPT_MASK) +#define RUBY_VM_SET_FINALIZER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, FINALIZER_INTERRUPT_MASK) +#define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TRAP_INTERRUPT_MASK) +#define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ~(th)->interrupt_mask & (ASYNC_ERRINFO_INTERRUPT_MASK|TRAP_INTERRUPT_MASK)) #define RUBY_VM_INTERRUPTED_ANY(th) ((th)->interrupt_flag & ~(th)->interrupt_mask) int rb_signal_buff_size(void);