Skip to content

Commit

Permalink
* (ruby_vm_send_signal): deal with signals properly.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Feb 12, 2010
1 parent 9073072 commit 6cf47b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
Sat Feb 13 07:11:57 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>

* (ruby_vm_send_signal): deal with signals properly.

Sat Nov 21 01:03:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>

* thread.c (rb_queue_mark): mark possible objects.
Expand Down
10 changes: 5 additions & 5 deletions thread.c
Expand Up @@ -1379,7 +1379,7 @@ rb_threadptr_execute_interrupts_rec(rb_thread_t *th, int sched_depth)
rb_vm_t *vm = GET_VM();

if (vm->main_thread == th) {
while (rb_signal_buff_size() && !(th->interrupt_flag & 0x08)) {
while (rb_signal_buff_size() && !(th->interrupt_flag & ruby_vm_signal_bit)) {
native_thread_yield();
}
}
Expand All @@ -1388,8 +1388,8 @@ rb_threadptr_execute_interrupts_rec(rb_thread_t *th, int sched_depth)

while (th->interrupt_flag) {
enum rb_thread_status status = th->status;
int timer_interrupt = th->interrupt_flag & 0x01;
int finalizer_interrupt = th->interrupt_flag & 0x04;
int timer_interrupt = th->interrupt_flag & ruby_vm_timer_bit;
int finalizer_interrupt = th->interrupt_flag & ruby_vm_finalizer_bit;
void *exec_signal;

th->status = THREAD_RUNNABLE;
Expand Down Expand Up @@ -2806,11 +2806,11 @@ ruby_vm_send_signal(rb_vm_t *vm, int sig)

if (sig <= 0 || sig >= RUBY_NSIG) return -1;
mth = vm->main_thread;
if (mth->interrupt_flag) return -1;
if (mth->interrupt_flag & ruby_vm_signal_bit) return -1;
prev_status = mth->status;
thread_debug("main_thread: %s, sig: %d\n",
thread_status_name(prev_status), sig);
mth->interrupt_flag |= 0x08;
mth->interrupt_flag |= ruby_vm_signal_bit;
rb_queue_push(&mth->queue.signal, (void *)INT2FIX(sig));
if (mth->status != THREAD_KILLED) mth->status = THREAD_RUNNABLE;
rb_threadptr_interrupt(mth);
Expand Down
15 changes: 11 additions & 4 deletions vm_core.h
Expand Up @@ -733,10 +733,17 @@ int ruby_thread_set_native(rb_thread_t *th);
#error "unsupported thread model"
#endif

#define RUBY_VM_SET_INTERRUPT(th) ((th)->interrupt_flag |= 0x02)
#define RUBY_VM_SET_TIMER_INTERRUPT(th) ((th)->interrupt_flag |= 0x01)
#define RUBY_VM_SET_FINALIZER_INTERRUPT(th) ((th)->interrupt_flag |= 0x04)
#define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & 0x02)
enum {
ruby_vm_timer_bit = 0x01,
ruby_vm_interrupt_bit = 0x02,
ruby_vm_finalizer_bit = 0x04,
ruby_vm_signal_bit = 0x08
};

#define RUBY_VM_SET_INTERRUPT(th) ((th)->interrupt_flag |= ruby_vm_interrupt_bit)
#define RUBY_VM_SET_TIMER_INTERRUPT(th) ((th)->interrupt_flag |= ruby_vm_timer_bit)
#define RUBY_VM_SET_FINALIZER_INTERRUPT(th) ((th)->interrupt_flag |= ruby_vm_finalizer_bit)
#define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ruby_vm_interrupt_bit)

void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
void rb_threadptr_signal_exit(rb_thread_t *th);
Expand Down

0 comments on commit 6cf47b3

Please sign in to comment.