From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 584491F97E; Thu, 22 Nov 2018 10:03:34 +0000 (UTC) Date: Thu, 22 Nov 2018 10:03:34 +0000 From: Eric Wong To: spew@80x24.org Subject: use rb_iom_schedule instead of native_sleep if necessary Message-ID: <20181122100334.evcxdcorsjrhqfj2@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline List-Id: diff --git a/thread.c b/thread.c index fd18081573..b1efeb2f4e 100644 --- a/thread.c +++ b/thread.c @@ -1006,7 +1006,10 @@ thread_join_sleep(VALUE arg) } while (target_th->status != THREAD_KILLED) { - if (!p->limit) { + if (!list_empty(&th->coros)) { + rb_iom_schedule(th, 0); + } + else if (!p->limit) { th->status = THREAD_STOPPED_FOREVER; th->vm->sleeper++; rb_check_deadlock(th->vm); @@ -1322,6 +1325,9 @@ rb_thread_sleep_forever(void) if (rb_tl_sched_p(th->ec)) { rb_iom_sleep(th, 0); } + else if (!list_empty(&th->coros)) { + rb_iom_schedule(th, 0); + } else { sleep_forever(th, SLEEP_SPURIOUS_CHECK); } @@ -1350,6 +1356,9 @@ rb_thread_wait_for(struct timeval time) if (rb_tl_sched_p(th->ec)) { rb_iom_sleep(th, &rel); } + else if (!list_empty(&th->coros)) { + rb_iom_schedule(th, &rel); + } else { sleep_hrtime(th, rel, SLEEP_SPURIOUS_CHECK); } diff --git a/thread_sync.c b/thread_sync.c index 91c775ccd6..fd4f7f91a8 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -884,7 +884,14 @@ sched_sleep(VALUE arg) rb_sched_waiter_sleep(sw, 0); } else if (!rb_tl_schedule_ready_p(sw->ec)) { - rb_thread_sleep_deadly_allow_spurious_wakeup(); + rb_thread_t *th = rb_ec_thread_ptr(sw->ec); + + if (list_empty(&th->coros)) { + rb_thread_sleep_deadly_allow_spurious_wakeup(); + } + else { + rb_iom_schedule(th, 0); + } } return Qnil; }