ruby-changes:52368
From: normal <ko1@a...>
Date: Tue, 28 Aug 2018 03:37:10 +0900 (JST)
Subject: [ruby-changes:52368] normal:r64577 (trunk): process.c: fix potential missed wakeups in r64576
normal 2018-08-28 03:37:04 +0900 (Tue, 28 Aug 2018) New Revision: 64577 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64577 Log: process.c: fix potential missed wakeups in r64576 Oddly, all existing test cases passed multiple times before this patch (even with --jit-wait), so this seems like a difficult failure to prove. Fixes: r64576 ("process.c: simplify SIGCHLD-based waitpid") Modified files: trunk/process.c Index: process.c =================================================================== --- process.c (revision 64576) +++ process.c (revision 64577) @@ -936,21 +936,19 @@ void rb_sigwait_fd_put(const rb_thread_t https://github.com/ruby/ruby/blob/trunk/process.c#L936 void rb_thread_sleep_interruptible(void); static int -sigwait_fd_migrate_signaled_p(struct waitpid_state *w) +waitpid_signal(struct waitpid_state *w) { - int signaled = FALSE; - rb_thread_t *th = w->ec ? rb_ec_thread_ptr(w->ec) : 0; - - if (th) rb_native_mutex_lock(&th->interrupt_lock); - - if (w->cond) { - rb_native_cond_signal(w->cond); - signaled = TRUE; + if (w->ec) { /* rb_waitpid */ + rb_threadptr_interrupt(rb_ec_thread_ptr(w->ec)); + return TRUE; } - - if (th) rb_native_mutex_unlock(&th->interrupt_lock); - - return signaled; + else { /* ruby_waitpid_locked */ + if (w->cond) { + rb_native_cond_signal(w->cond); + return TRUE; + } + } + return FALSE; } /* @@ -964,10 +962,10 @@ sigwait_fd_migrate_sleeper(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/process.c#L962 struct waitpid_state *w = 0; list_for_each(&vm->waiting_pids, w, wnode) { - if (sigwait_fd_migrate_signaled_p(w)) return; + if (waitpid_signal(w)) return; } list_for_each(&vm->waiting_grps, w, wnode) { - if (sigwait_fd_migrate_signaled_p(w)) return; + if (waitpid_signal(w)) return; } } @@ -995,14 +993,7 @@ waitpid_each(struct list_head *head) https://github.com/ruby/ruby/blob/trunk/process.c#L993 w->ret = ret; list_del_init(&w->wnode); - if (w->ec) { /* rb_waitpid */ - rb_threadptr_interrupt(rb_ec_thread_ptr(w->ec)); - } - else { /* ruby_waitpid_locked */ - if (w->cond) { - rb_native_cond_signal(w->cond); - } - } + waitpid_signal(w); } } #else -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/