mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
use ractor_wakeup()
Use ractor_wakeup() for same code.
This commit is contained in:
parent
d961f14df3
commit
03d1850bfa
1 changed files with 27 additions and 28 deletions
55
ractor.c
55
ractor.c
|
@ -491,6 +491,31 @@ ractor_try_receive(rb_execution_context_t *ec, rb_ractor_t *r)
|
|||
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)
|
|||
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)
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue