ruby-changes:15604
From: mame <ko1@a...>
Date: Tue, 27 Apr 2010 21:27:32 +0900 (JST)
Subject: [ruby-changes:15604] Ruby:r27513 (trunk): * eval.c (ruby_cleanup): before cleanup, check signal buffer and run
mame 2010-04-27 21:27:13 +0900 (Tue, 27 Apr 2010) New Revision: 27513 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27513 Log: * eval.c (ruby_cleanup): before cleanup, check signal buffer and run handler if any. [ruby-core:20970] * thread.c (rb_threadptr_check_signal): separeted from timer_thread_function. Modified files: trunk/ChangeLog trunk/eval.c trunk/test/ruby/test_signal.rb trunk/thread.c Index: ChangeLog =================================================================== --- ChangeLog (revision 27512) +++ ChangeLog (revision 27513) @@ -1,3 +1,11 @@ +Tue Apr 27 21:24:40 2010 Yusuke Endoh <mame@t...> + + * eval.c (ruby_cleanup): before cleanup, check signal buffer and run + handler if any. [ruby-core:20970] + + * thread.c (rb_threadptr_check_signal): separeted from + timer_thread_function. + Tue Apr 27 18:00:50 2010 Nobuyoshi Nakada <nobu@r...> * lib/net/smtp.rb (Net::SMTP#rcptto_list): fixed typo. Index: thread.c =================================================================== --- thread.c (revision 27512) +++ thread.c (revision 27513) @@ -290,7 +290,7 @@ native_mutex_unlock(&th->interrupt_lock); } -static void +void rb_threadptr_interrupt(rb_thread_t *th) { native_mutex_lock(&th->interrupt_lock); @@ -2651,18 +2651,13 @@ int rb_get_next_signal(void); -static void -timer_thread_function(void *arg) +void +rb_threadptr_check_signal(rb_thread_t *mth) { - rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */ int sig; - rb_thread_t *mth; - /* for time slice */ - RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread); + /* mth must be main_thread */ - /* check signal */ - mth = vm->main_thread; if (!mth->exec_signal && (sig = rb_get_next_signal()) > 0) { enum rb_thread_status prev_status = mth->status; thread_debug("main_thread: %s, sig: %d\n", @@ -2672,7 +2667,20 @@ rb_threadptr_interrupt(mth); mth->status = prev_status; } +} +static void +timer_thread_function(void *arg) +{ + rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */ + rb_thread_t *mth; + + /* for time slice */ + RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread); + + /* check signal */ + rb_threadptr_check_signal(vm->main_thread); + #if 0 /* prove profiler */ if (vm->prove_profile.enable) { Index: eval.c =================================================================== --- eval.c (revision 27512) +++ eval.c (revision 27513) @@ -127,7 +127,13 @@ volatile VALUE errs[2]; rb_thread_t *th = GET_THREAD(); int nerr; + void rb_threadptr_interrupt(rb_thread_t *th); + void rb_threadptr_check_signal(rb_thread_t *mth); + rb_threadptr_interrupt(th); + rb_threadptr_check_signal(th); + RUBY_VM_CHECK_INTS(); + errs[1] = th->errinfo; th->safe_level = 0; ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]); Index: test/ruby/test_signal.rb =================================================================== --- test/ruby/test_signal.rb (revision 27512) +++ test/ruby/test_signal.rb (revision 27513) @@ -36,7 +36,7 @@ end def test_exit_action - return unless have_fork? # snip this test + return unless have_fork? # skip this test begin r, w = IO.pipe r0, w0 = IO.pipe @@ -166,4 +166,17 @@ Signal.trap(:INT, oldtrap) if oldtrap end end + + def test_kill_immediately_before_termination + return unless have_fork? # skip this test + + r, w = IO.pipe + pid = Process.fork do + r.close + Signal.trap(:USR1) { w.syswrite("foo") } + Process.kill :USR1, $$ + end + w.close + assert_equal(r.read, "foo") + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/