ruby-changes:51584
From: normal <ko1@a...>
Date: Sat, 30 Jun 2018 09:52:03 +0900 (JST)
Subject: [ruby-changes:51584] normal:r63795 (trunk): use SIGCHLD_LOSSY to enable waitpid polling mode
normal 2018-06-30 09:51:57 +0900 (Sat, 30 Jun 2018) New Revision: 63795 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63795 Log: use SIGCHLD_LOSSY to enable waitpid polling mode Some systems lack SIGCHLD or have incomplete SIGCHLD implementations. So enable polling mode for them. [ruby-core:87705] [Bug #14867] Modified files: trunk/mjit.c trunk/process.c trunk/signal.c trunk/thread_pthread.c trunk/vm_core.h Index: mjit.c =================================================================== --- mjit.c (revision 63794) +++ mjit.c (revision 63795) @@ -408,7 +408,7 @@ exec_process(const char *path, char *con https://github.com/ruby/ruby/blob/trunk/mjit.c#L408 { int stat, exit_code = -2; pid_t pid; - rb_vm_t *vm = RUBY_SIGCHLD ? GET_VM() : 0; + rb_vm_t *vm = (RUBY_SIGCHLD || SIGCHLD_LOSSY) ? GET_VM() : 0; rb_nativethread_cond_t cond; if (vm) { Index: process.c =================================================================== --- process.c (revision 63794) +++ process.c (revision 63795) @@ -1126,7 +1126,7 @@ rb_waitpid(rb_pid_t pid, int *st, int fl https://github.com/ruby/ruby/blob/trunk/process.c#L1126 waitpid_state_init(&w, pid, flags); w.ec = GET_EC(); - if (RUBY_SIGCHLD) { + if (RUBY_SIGCHLD || SIGCHLD_LOSSY) { waitpid_wait(&w); } else { Index: signal.c =================================================================== --- signal.c (revision 63794) +++ signal.c (revision 63795) @@ -1066,7 +1066,7 @@ void ruby_waitpid_all(rb_vm_t *); /* pro https://github.com/ruby/ruby/blob/trunk/signal.c#L1066 void ruby_sigchld_handler(rb_vm_t *vm) { - if (ATOMIC_EXCHANGE(sigchld_hit, 0)) { + if (SIGCHLD_LOSSY || ATOMIC_EXCHANGE(sigchld_hit, 0)) { ruby_waitpid_all(vm); } } Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 63794) +++ thread_pthread.c (revision 63795) @@ -1375,6 +1375,16 @@ timer_thread_sleep(rb_global_vm_lock_t* https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1375 need_polling = !ubf_threads_empty(); + if (SIGCHLD_LOSSY && !need_polling) { + rb_vm_t *vm = container_of(gvl, rb_vm_t, gvl); + + rb_native_mutex_lock(&vm->waitpid_lock); + if (!list_empty(&vm->waiting_pids) || !list_empty(&vm->waiting_grps)) { + need_polling = 1; + } + rb_native_mutex_unlock(&vm->waitpid_lock); + } + if (gvl->waiting > 0 || need_polling) { /* polling (TIME_QUANTUM_USEC usec) */ result = poll(pollfds, 1, TIME_QUANTUM_USEC/1000); Index: vm_core.h =================================================================== --- vm_core.h (revision 63794) +++ vm_core.h (revision 63795) @@ -100,6 +100,13 @@ https://github.com/ruby/ruby/blob/trunk/vm_core.h#L100 # define RUBY_SIGCHLD (0) #endif +/* platforms with broken or non-existent SIGCHLD work by polling */ +#if defined(__APPLE__) || defined(__WIN32__) +# define SIGCHLD_LOSSY (1) +#else +# define SIGCHLD_LOSSY (0) +#endif + #ifdef HAVE_STDARG_PROTOTYPES #include <stdarg.h> #define va_init_list(a,b) va_start((a),(b)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/