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 1F6471F87F; Wed, 21 Nov 2018 09:55:21 +0000 (UTC) Date: Wed, 21 Nov 2018 09:55:20 +0000 From: Eric Wong To: spew@80x24.org Subject: switch disable on mutex Message-ID: <20181121095520.v4ddgpn6lufbvuvt@whir> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline List-Id: diff --git a/iom_pingable_common.h b/iom_pingable_common.h index 07841b44ca3..2e8c880f68d 100644 --- a/iom_pingable_common.h +++ b/iom_pingable_common.h @@ -214,7 +214,7 @@ rb_iom_fd(const rb_thread_t *th) static int rb_iom_schedule_p(const rb_thread_t *th) { - return rb_tl_sched_p(th->ec); + return rb_tl_sched_p(th->ec) && rb_tl_switchable(th->ec); } static void diff --git a/iom_select.h b/iom_select.h index 841104fb017..db51ac7a75f 100644 --- a/iom_select.h +++ b/iom_select.h @@ -541,13 +541,21 @@ rb_iom_schedule_p(const rb_thread_t *th) { rb_iom_t *iom = th->vm->iom; - if (rb_tl_sched_p(th->ec)) return 1; + if (!rb_tl_switchable(th->ec)) { + return 0; + } + if (rb_tl_sched_p(th->ec)) { + return 1; + } + /* + * select is different from the epoll/kqueue iom implementations + * since it's O(n) every call anyways, so we might as well run + * select() so that it covers as many FDs as possible + * FIXME: we sometimes miss wakeups if we use select for waiting + * on native threads unfortunately: + */ if (iom && list_empty(&iom->c.blockers) && iom_events_pending(th->vm)) { - /* - * FIXME: we sometimes miss wakeups if we use select for waiting - * on native threads unfortunately: - */ return 1; } return 0; diff --git a/vm_core.h b/vm_core.h index 9e10b321da2..2244afb5248 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1846,6 +1846,9 @@ rb_tl_switchable(const rb_execution_context_t *ec) /* dangerous, don't allow switching inside trap handler: */ if (ec->interrupt_mask & TRAP_INTERRUPT_MASK) return 0; + /* don't switch if a Mutex is held */ + if (th->keeping_mutexes) return 0; + /* auto-fibers can switch away to root fiber */ if (rb_tl_sched_p(ec)) return 1;