From fe2f89af9ad6bd87ec91b7042593bc8c7247708b Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 18 Aug 2018 09:07:36 +0000 Subject: thread.c (sleep_*): reduce the effect of spurious interrupts Spurious interrupts from SIGCHLD cause Mutex#sleep (via ConditionVariable#wait) to return early and breaks some use cases. Since these are outside the programs's control with MJIT, we will only consider pending interrupts (e.g. those from Thread#run) and signals which cause a Ruby-level Signal.trap handler to fire as "spurious" wakeups. [ruby-core:88537] [Feature #15002] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- signal.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'signal.c') diff --git a/signal.c b/signal.c index 31dd3bbdb0..326179f383 100644 --- a/signal.c +++ b/signal.c @@ -1039,7 +1039,7 @@ sig_do_nothing(int sig) } #endif -static void +static int signal_exec(VALUE cmd, int safe, int sig) { rb_execution_context_t *ec = GET_EC(); @@ -1053,7 +1053,7 @@ signal_exec(VALUE cmd, int safe, int sig) * 3. rb_signal_exec runs on queued signal */ if (IMMEDIATE_P(cmd)) - return; + return FALSE; ec->interrupt_mask |= TRAP_INTERRUPT_MASK; EC_PUSH_TAG(ec); @@ -1069,6 +1069,7 @@ signal_exec(VALUE cmd, int safe, int sig) /* XXX: should be replaced with rb_threadptr_pending_interrupt_enque() */ EC_JUMP_TAG(ec, state); } + return TRUE; } void @@ -1093,7 +1094,8 @@ ruby_sigchld_handler(rb_vm_t *vm) } } -void +/* returns true if a trap handler was run, false otherwise */ +int rb_signal_exec(rb_thread_t *th, int sig) { rb_vm_t *vm = GET_VM(); @@ -1131,8 +1133,9 @@ rb_signal_exec(rb_thread_t *th, int sig) rb_threadptr_signal_exit(th); } else { - signal_exec(cmd, safe, sig); + return signal_exec(cmd, safe, sig); } + return FALSE; } static sighandler_t -- cgit v1.2.3