diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-02-09 19:39:56 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 19:39:56 +1300 |
commit | 5f69a7f60467fa58c2f998daffab43e118bff36c (patch) | |
tree | f60e3a5add29eb9cc7e68433c4e373e2a2facab7 /thread_sync.c | |
parent | 3c593f28ede99b77d4fe3258f9bda78dcee238a3 (diff) |
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.
Notes
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'thread_sync.c')
-rw-r--r-- | thread_sync.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/thread_sync.c b/thread_sync.c index 8295b3d8c2..9932abde11 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -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)) { |