Expose scheduler as public interface & bug fixes. (#3945)

* Rename `rb_scheduler` to `rb_fiber_scheduler`.

* Use public interface if available.

* Use `rb_check_funcall` where possible.

* Don't use `unblock` unless the fiber was non-blocking.
This commit is contained in:
Samuel Williams 2021-02-09 19:39:56 +13:00 committed by GitHub
parent 3c593f28ed
commit 5f69a7f604
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2021-02-09 15:40:27 +09:00
Merged-By: ioquatix <samuel@codeotaku.com>
18 changed files with 356 additions and 245 deletions

View file

@ -32,8 +32,8 @@ sync_wakeup(struct list_head *head, long max)
if (cur->th->status != THREAD_KILLED) {
if (cur->th->scheduler != Qnil) {
rb_scheduler_unblock(cur->th->scheduler, cur->self, rb_fiberptr_self(cur->fiber));
if (cur->th->scheduler != Qnil && rb_fiberptr_blocking(cur->fiber) == 0) {
rb_fiber_scheduler_unblock(cur->th->scheduler, cur->self, rb_fiberptr_self(cur->fiber));
} else {
rb_threadptr_interrupt(cur->th);
cur->th->status = THREAD_RUNNABLE;
@ -267,8 +267,8 @@ mutex_owned_p(rb_fiber_t *fiber, rb_mutex_t *mutex)
}
}
static VALUE call_rb_scheduler_block(VALUE mutex) {
return rb_scheduler_block(rb_scheduler_current(), mutex, Qnil);
static VALUE call_rb_fiber_scheduler_block(VALUE mutex) {
return rb_fiber_scheduler_block(rb_fiber_scheduler_current(), mutex, Qnil);
}
static VALUE
@ -302,7 +302,7 @@ do_mutex_lock(VALUE self, int interruptible_p)
}
while (mutex->fiber != fiber) {
VALUE scheduler = rb_scheduler_current();
VALUE scheduler = rb_fiber_scheduler_current();
if (scheduler != Qnil) {
COROUTINE_STACK_LOCAL(struct sync_waiter, w);
w->self = self;
@ -311,7 +311,7 @@ do_mutex_lock(VALUE self, int interruptible_p)
list_add_tail(&mutex->waitq, &w->node);
rb_ensure(call_rb_scheduler_block, self, delete_from_waitq, (VALUE)w);
rb_ensure(call_rb_fiber_scheduler_block, self, delete_from_waitq, (VALUE)w);
if (!mutex->fiber) {
mutex->fiber = fiber;
@ -437,8 +437,8 @@ rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t *th, rb_fiber_t *fiber)
list_for_each_safe(&mutex->waitq, cur, next, node) {
list_del_init(&cur->node);
if (cur->th->scheduler != Qnil) {
rb_scheduler_unblock(cur->th->scheduler, cur->self, rb_fiberptr_self(cur->fiber));
if (cur->th->scheduler != Qnil && rb_fiberptr_blocking(cur->fiber) == 0) {
rb_fiber_scheduler_unblock(cur->th->scheduler, cur->self, rb_fiberptr_self(cur->fiber));
goto found;
} else {
switch (cur->th->status) {
@ -545,9 +545,9 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
rb_mutex_unlock(self);
time_t beg = time(0);
VALUE scheduler = rb_scheduler_current();
VALUE scheduler = rb_fiber_scheduler_current();
if (scheduler != Qnil) {
rb_scheduler_kernel_sleep(scheduler, timeout);
rb_fiber_scheduler_kernel_sleep(scheduler, timeout);
mutex_lock_uninterruptible(self);
} else {
if (NIL_P(timeout)) {