ruby-changes:64985
From: Koichi <ko1@a...>
Date: Fri, 22 Jan 2021 02:49:35 +0900 (JST)
Subject: [ruby-changes:64985] 03d1850bfa (master): use ractor_wakeup()
https://git.ruby-lang.org/ruby.git/commit/?id=03d1850bfa From 03d1850bfaa1c279fe5cc79f4bb2128f50c5b9e5 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Fri, 22 Jan 2021 02:48:31 +0900 Subject: use ractor_wakeup() Use ractor_wakeup() for same code. diff --git a/ractor.c b/ractor.c index 420b205..e435306 100644 --- a/ractor.c +++ b/ractor.c @@ -491,6 +491,31 @@ ractor_try_receive(rb_execution_context_t *ec, rb_ractor_t *r) https://github.com/ruby/ruby/blob/trunk/ractor.c#L491 return ractor_basket_accept(&basket); } +static bool +ractor_sleeping_by(const rb_ractor_t *r, enum ractor_wait_status wait_status) +{ + return (r->sync.wait.status & wait_status) && r->sync.wait.wakeup_status == wakeup_none; +} + +static bool +ractor_wakeup(rb_ractor_t *r, enum ractor_wait_status wait_status, enum ractor_wakeup_status wakeup_status) +{ + ASSERT_ractor_locking(r); + + // fprintf(stderr, "%s r:%p status:%s/%s wakeup_status:%s/%s\n", __func__, r, + // wait_status_str(r->sync.wait.status), wait_status_str(wait_status), + // wakeup_status_str(r->sync.wait.wakeup_status), wakeup_status_str(wakeup_status)); + + if (ractor_sleeping_by(r, wait_status)) { + r->sync.wait.wakeup_status = wakeup_status; + rb_native_cond_signal(&r->sync.cond); + return true; + } + else { + return false; + } +} + static void * ractor_sleep_wo_gvl(void *ptr) { @@ -513,9 +538,8 @@ ractor_sleep_interrupt(void *ptr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L538 rb_ractor_t *r = ptr; RACTOR_LOCK(r); - if (r->sync.wait.wakeup_status == wakeup_none) { - r->sync.wait.wakeup_status = wakeup_by_interrupt; - rb_native_cond_signal(&r->sync.cond); + { + ractor_wakeup(r, wait_receiving | wait_taking | wait_yielding, wakeup_by_interrupt); } RACTOR_UNLOCK(r); } @@ -580,31 +604,6 @@ ractor_sleep(rb_execution_context_t *ec, rb_ractor_t *cr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L604 } } -static bool -ractor_sleeping_by(const rb_ractor_t *r, enum ractor_wait_status wait_status) -{ - return (r->sync.wait.status & wait_status) && r->sync.wait.wakeup_status == wakeup_none; -} - -static bool -ractor_wakeup(rb_ractor_t *r, enum ractor_wait_status wait_status, enum ractor_wakeup_status wakeup_status) -{ - ASSERT_ractor_locking(r); - - // fprintf(stderr, "%s r:%p status:%s/%s wakeup_status:%s/%s\n", __func__, r, - // wait_status_str(r->sync.wait.status), wait_status_str(wait_status), - // wakeup_status_str(r->sync.wait.wakeup_status), wakeup_status_str(wakeup_status)); - - if (ractor_sleeping_by(r, wait_status)) { - r->sync.wait.wakeup_status = wakeup_status; - rb_native_cond_signal(&r->sync.cond); - return true; - } - else { - return false; - } -} - static void ractor_register_taking(rb_ractor_t *r, rb_ractor_t *cr) { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/