diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-06 05:22:00 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-06 05:22:00 +0000 |
commit | 194a6a2c68e9c8a3536b24db18ceac87535a6051 (patch) | |
tree | 1d6074813a7c515b81e61e451422e559541ba79d /process.c | |
parent | 828158704c2a03f7c780f5dd4f9ffc88b709c4a7 (diff) | |
download | ruby-194a6a2c68e9c8a3536b24db18ceac87535a6051.tar.gz |
thread_pthread.c: restore timer-thread for now :<
[ruby-core:88306]
Revert "process.c: ensure th->interrupt lock is held when migrating"
This reverts commit 5ca416bdf6b6785cb20f139c2c514eda005fe42f (r64201)
Revert "process.c (rb_waitpid): reduce sigwait_fd bouncing"
This reverts commit 217bdd776fbeea3bfd0b9324eefbfcec3b1ccb3e (r64200).
Revert "test/ruby/test_thread.rb (test_thread_timer_and_interrupt): add timeouts"
This reverts commit 9f395f11202fc3c7edbd76f5aa6ce1f8a1e752a9 (r64199).
Revert "thread_pthread.c (native_sleep): reduce ppoll sleeps"
This reverts commit b3aa256c4d43d3d7e9975ec18eb127f45f623c9b (r64193).
Revert "thread.c (consume_communication_pipe): do not retry after short read"
This reverts commit 291a82f748de56e65fac10edefc51ec7a54a82d4 (r64185).
Revert "test/ruby/test_io.rb (test_race_gets_and_close): timeout each thread"
This reverts commit 3dbd8d1f66537f968f0461ed8547460b3b1241b3 (r64184).
Revert "thread_pthread.c (gvl_acquire_common): persist timeout across calls"
This reverts commit 8c2ae6e3ed072b06fc3cbc34fa8a14b2acbb49d5 (r64165).
Revert "test/ruby/test_io.rb (test_race_gets_and_close): use SIGABRT on timeout"
This reverts commit 931cda4db8afd6b544a8d85a6815765a9c417213 (r64135).
Revert "thread_pthread.c (gvl_yield): do ubf wakeups when uncontended"
This reverts commit 508f00314f46c08b6e9b0141c01355d24954260c (r64133).
Revert "thread_pthread.h (native_thread_data): split condvars on some platforms"
This reverts commit a038bf238bd9a24bf1e1622f618a27db261fc91b (r64124).
Revert "process.c (waitpid_nogvl): prevent conflicting use of sleep_cond"
This reverts commit 7018acc946882f21d519af7c42ccf84b22a46b27 (r64117).
Revert "thread_pthread.c (rb_sigwait_sleep): th may be 0 from MJIT"
This reverts commit 56491afc7916fb24f5c4dc2c632fb93fa7063992 (r64116).
Revert "thread*.c: waiting on sigwait_fd performs periodic ubf wakeups"
This reverts commit ab47a57a46e70634d049e4da20a5441c7a14cdec (r64115).
Revert "thread_pthread.c (gvl_destroy): make no-op on GVL bits"
This reverts commit 95cae748171f4754b97f4ba54da2ae62a8d484fd (r64114).
Revert "thread_pthread.c (rb_sigwait_sleep): fix uninitialized poll set in UBF case"
This reverts commit 4514362948fdb914c6138b12d961d92e9c0fee6c (r64113).
Revert "thread_pthread.c (rb_sigwait_sleep): re-fix [Bug #5343] harder"
This reverts commit 26b8a70bb309c7a367b9134045508b5b5a580a77 (r64111).
Revert "thread.c: move ppoll wrapper into thread_pthread.c"
This reverts commit 3dc7727d22fecbc355597edda25d2a245bf55ba1 (r64110).
Revert "thread.c: move ppoll wrapper before thread_pthread.c"
This reverts commit 2fa1e2e3c3c5c4b3ce84730dee4bcbe9d81b8e35 (r64109).
Revert "thread_pthread.c (ubf_select): refix [Bug #5343]"
This reverts commit 4c1ab82f0623eca91a95d2a44053be22bbce48ad (r64108).
Revert "thread_win32.c: suppress warnings by -Wsuggest-attribute"
This reverts commit 6a9b63e39075c53870933fbac5c1065f7d22047c (r64159).
Revert "thread_pthread: remove timer-thread by restructuring GVL"
This reverts commit 708bfd21156828526fe72de2cedecfaca6647dc1 (r64107).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 140 |
1 files changed, 9 insertions, 131 deletions
@@ -928,7 +928,6 @@ struct waitpid_state { int status; int options; int errnum; - int sigwait_fd; }; void rb_native_mutex_lock(rb_nativethread_lock_t *); @@ -937,65 +936,13 @@ void rb_native_cond_signal(rb_nativethread_cond_t *); void rb_native_cond_wait(rb_nativethread_cond_t *, rb_nativethread_lock_t *); rb_nativethread_cond_t *rb_sleep_cond_get(const rb_execution_context_t *); void rb_sleep_cond_put(rb_nativethread_cond_t *); -int rb_sigwait_fd_get(const rb_thread_t *); -void rb_sigwait_sleep(const rb_thread_t *, int fd, const struct timespec *); -void rb_sigwait_fd_put(const rb_thread_t *, int fd); - -static int -sigwait_fd_migrate_signaled_p(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 (th) rb_native_mutex_unlock(&th->interrupt_lock); - - return signaled; -} - -/* - * When a thread is done using sigwait_fd and there are other threads - * sleeping on waitpid, we must kick one of the threads out of - * rb_native_cond_wait so it can switch to rb_sigwait_sleep - */ -static void -sigwait_fd_migrate_sleeper(rb_vm_t *vm) -{ - struct waitpid_state *w = 0; - - list_for_each(&vm->waiting_pids, w, wnode) { - if (sigwait_fd_migrate_signaled_p(w)) return; - } - list_for_each(&vm->waiting_grps, w, wnode) { - if (sigwait_fd_migrate_signaled_p(w)) return; - } -} - -void -rb_sigwait_fd_migrate(rb_vm_t *vm) -{ - rb_native_mutex_lock(&vm->waitpid_lock); - sigwait_fd_migrate_sleeper(vm); - rb_native_mutex_unlock(&vm->waitpid_lock); -} static void waitpid_notify(struct waitpid_state *w, rb_pid_t ret) { w->ret = ret; list_del_init(&w->wnode); - if (w->cond) { - rb_native_cond_signal(w->cond); - } - else { - /* w is owned by this thread */ - } + rb_native_cond_signal(w->cond); } #ifdef _WIN32 /* for spawnvp result from mjit.c */ @@ -1007,7 +954,7 @@ waitpid_notify(struct waitpid_state *w, rb_pid_t ret) #endif extern volatile unsigned int ruby_nocldwait; /* signal.c */ -/* called by timer thread or thread which acquired sigwait_fd */ +/* called by timer thread */ static void waitpid_each(struct list_head *head) { @@ -1061,17 +1008,6 @@ waitpid_state_init(struct waitpid_state *w, rb_pid_t pid, int options) w->options = options; } -static const struct timespec * -sigwait_sleep_time(void) -{ - if (SIGCHLD_LOSSY) { - static const struct timespec busy_wait = { 0, 100000000 }; - - return &busy_wait; - } - return 0; -} - /* * must be called with vm->waitpid_lock held, this is not interruptible */ @@ -1090,31 +1026,13 @@ ruby_waitpid_locked(rb_vm_t *vm, rb_pid_t pid, int *status, int options, if (w.ret == -1) w.errnum = errno; } else { + w.cond = cond; w.ec = 0; - w.sigwait_fd = -1; list_add(w.pid > 0 ? &vm->waiting_pids : &vm->waiting_grps, &w.wnode); do { - if (w.sigwait_fd < 0) - w.sigwait_fd = rb_sigwait_fd_get(0); - - if (w.sigwait_fd >= 0) { - w.cond = 0; - rb_native_mutex_unlock(&vm->waitpid_lock); - rb_sigwait_sleep(0, w.sigwait_fd, sigwait_sleep_time()); - rb_native_mutex_lock(&vm->waitpid_lock); - } - else { - w.cond = cond; - rb_native_cond_wait(w.cond, &vm->waitpid_lock); - } + rb_native_cond_wait(w.cond, &vm->waitpid_lock); } while (!w.ret); list_del(&w.wnode); - - /* we're done, maybe other waitpid callers are not: */ - if (w.sigwait_fd >= 0) { - rb_sigwait_fd_put(0, w.sigwait_fd); - sigwait_fd_migrate_sleeper(vm); - } } if (status) { *status = w.status; @@ -1129,10 +1047,7 @@ waitpid_wake(void *x) struct waitpid_state *w = x; /* th->interrupt_lock is already held by rb_threadptr_interrupt_common */ - if (w->cond) - rb_native_cond_signal(w->cond); - else - rb_thread_wakeup_timer_thread(0); /* kick sigwait_fd */ + rb_native_cond_signal(w->cond); } static void * @@ -1147,40 +1062,11 @@ waitpid_nogvl(void *x) * by the time we enter this. And we may also be interrupted. */ if (!w->ret && !RUBY_VM_INTERRUPTED_ANY(w->ec)) { - if (w->sigwait_fd < 0) - w->sigwait_fd = rb_sigwait_fd_get(th); - - if (w->sigwait_fd >= 0) { - rb_nativethread_cond_t *cond = w->cond; - - w->cond = 0; - rb_native_mutex_unlock(&th->interrupt_lock); - rb_sigwait_sleep(th, w->sigwait_fd, sigwait_sleep_time()); - rb_native_mutex_lock(&th->interrupt_lock); - w->cond = cond; + if (SIGCHLD_LOSSY) { + rb_thread_wakeup_timer_thread(); } - else { - if (!w->cond) - w->cond = rb_sleep_cond_get(w->ec); - - /* another thread calling rb_sigwait_sleep will process - * signals for us */ - if (SIGCHLD_LOSSY) { - rb_thread_wakeup_timer_thread(0); - } - rb_native_cond_wait(w->cond, &th->interrupt_lock); - } - } - - /* - * we must release th->native_thread_data.sleep_cond when - * re-acquiring GVL: - */ - if (w->cond) { - rb_sleep_cond_put(w->cond); - w->cond = 0; + rb_native_cond_wait(w->cond, &th->interrupt_lock); } - rb_native_mutex_unlock(&th->interrupt_lock); return 0; @@ -1210,15 +1096,8 @@ waitpid_cleanup(VALUE x) list_del(&w->wnode); rb_native_mutex_unlock(&vm->waitpid_lock); } + rb_sleep_cond_put(w->cond); - /* we may have never released and re-acquired GVL */ - if (w->cond) - rb_sleep_cond_put(w->cond); - - if (w->sigwait_fd >= 0) { - rb_sigwait_fd_put(rb_ec_thread_ptr(w->ec), w->sigwait_fd); - rb_sigwait_fd_migrate(rb_ec_vm_ptr(w->ec)); - } return Qfalse; } @@ -1245,7 +1124,6 @@ waitpid_wait(struct waitpid_state *w) } else { w->cond = rb_sleep_cond_get(w->ec); - w->sigwait_fd = -1; /* order matters, favor specified PIDs rather than -1 or 0 */ list_add(w->pid > 0 ? &vm->waiting_pids : &vm->waiting_grps, &w->wnode); } |