summaryrefslogtreecommitdiff
path: root/scheduler.c
diff options
context:
space:
mode:
Diffstat (limited to 'scheduler.c')
-rw-r--r--scheduler.c84
1 files changed, 39 insertions, 45 deletions
diff --git a/scheduler.c b/scheduler.c
index 88db433..4687231 100644
--- a/scheduler.c
+++ b/scheduler.c
@@ -9,7 +9,7 @@
**********************************************************************/
#include "vm_core.h"
-#include "internal/scheduler.h"
+#include "ruby/fiber/scheduler.h"
#include "ruby/io.h"
static ID id_close;
@@ -25,7 +25,7 @@ static ID id_io_write;
static ID id_io_wait;
void
-Init_Scheduler(void)
+Init_Fiber_Scheduler(void)
{
id_close = rb_intern_const("close");
@@ -41,7 +41,7 @@ Init_Scheduler(void)
}
VALUE
-rb_scheduler_get(void)
+rb_fiber_scheduler_get(void)
{
rb_thread_t *thread = GET_THREAD();
VM_ASSERT(thread);
@@ -50,14 +50,14 @@ rb_scheduler_get(void)
}
VALUE
-rb_scheduler_set(VALUE scheduler)
+rb_fiber_scheduler_set(VALUE scheduler)
{
rb_thread_t *thread = GET_THREAD();
VM_ASSERT(thread);
// We invoke Scheduler#close when setting it to something else, to ensure the previous scheduler runs to completion before changing the scheduler. That way, we do not need to consider interactions, e.g., of a Fiber from the previous scheduler with the new scheduler.
if (thread->scheduler != Qnil) {
- rb_scheduler_close(thread->scheduler);
+ rb_fiber_scheduler_close(thread->scheduler);
}
thread->scheduler = scheduler;
@@ -66,7 +66,7 @@ rb_scheduler_set(VALUE scheduler)
}
static VALUE
-rb_threadptr_scheduler_current(rb_thread_t *thread)
+rb_fiber_scheduler_current_for_threadptr(rb_thread_t *thread)
{
VM_ASSERT(thread);
@@ -78,18 +78,18 @@ rb_threadptr_scheduler_current(rb_thread_t *thread)
}
VALUE
-rb_scheduler_current(void)
+rb_fiber_scheduler_current(void)
{
- return rb_threadptr_scheduler_current(GET_THREAD());
+ return rb_fiber_scheduler_current_for_threadptr(GET_THREAD());
}
-VALUE rb_thread_scheduler_current(VALUE thread)
+VALUE rb_fiber_scheduler_current_for_thread(VALUE thread)
{
- return rb_threadptr_scheduler_current(rb_thread_ptr(thread));
+ return rb_fiber_scheduler_current_for_threadptr(rb_thread_ptr(thread));
}
VALUE
-rb_scheduler_close(VALUE scheduler)
+rb_fiber_scheduler_close(VALUE scheduler)
{
if (rb_respond_to(scheduler, id_close)) {
return rb_funcall(scheduler, id_close, 0);
@@ -99,7 +99,7 @@ rb_scheduler_close(VALUE scheduler)
}
VALUE
-rb_scheduler_timeout(struct timeval *timeout)
+rb_fiber_scheduler_make_timeout(struct timeval *timeout)
{
if (timeout) {
return rb_float_new((double)timeout->tv_sec + (0.000001f * timeout->tv_usec));
@@ -109,80 +109,74 @@ rb_scheduler_timeout(struct timeval *timeout)
}
VALUE
-rb_scheduler_kernel_sleep(VALUE scheduler, VALUE timeout)
+rb_fiber_scheduler_kernel_sleep(VALUE scheduler, VALUE timeout)
{
return rb_funcall(scheduler, id_kernel_sleep, 1, timeout);
}
VALUE
-rb_scheduler_kernel_sleepv(VALUE scheduler, int argc, VALUE * argv)
+rb_fiber_scheduler_kernel_sleepv(VALUE scheduler, int argc, VALUE * argv)
{
return rb_funcallv(scheduler, id_kernel_sleep, argc, argv);
}
-int
-rb_scheduler_supports_process_wait(VALUE scheduler)
-{
- return rb_respond_to(scheduler, id_process_wait);
-}
-
VALUE
-rb_scheduler_process_wait(VALUE scheduler, rb_pid_t pid, int flags)
+rb_fiber_scheduler_process_wait(VALUE scheduler, rb_pid_t pid, int flags)
{
- return rb_funcall(scheduler, id_process_wait, 2, PIDT2NUM(pid), RB_INT2NUM(flags));
+ VALUE arguments[] = {
+ PIDT2NUM(pid), RB_INT2NUM(flags)
+ };
+
+ return rb_check_funcall(scheduler, id_process_wait, 2, arguments);
}
VALUE
-rb_scheduler_block(VALUE scheduler, VALUE blocker, VALUE timeout)
+rb_fiber_scheduler_block(VALUE scheduler, VALUE blocker, VALUE timeout)
{
return rb_funcall(scheduler, id_block, 2, blocker, timeout);
}
VALUE
-rb_scheduler_unblock(VALUE scheduler, VALUE blocker, VALUE fiber)
+rb_fiber_scheduler_unblock(VALUE scheduler, VALUE blocker, VALUE fiber)
{
return rb_funcall(scheduler, id_unblock, 2, blocker, fiber);
}
VALUE
-rb_scheduler_io_wait(VALUE scheduler, VALUE io, VALUE events, VALUE timeout)
+rb_fiber_scheduler_io_wait(VALUE scheduler, VALUE io, VALUE events, VALUE timeout)
{
return rb_funcall(scheduler, id_io_wait, 3, io, events, timeout);
}
VALUE
-rb_scheduler_io_wait_readable(VALUE scheduler, VALUE io)
+rb_fiber_scheduler_io_wait_readable(VALUE scheduler, VALUE io)
{
- return rb_scheduler_io_wait(scheduler, io, RB_UINT2NUM(RUBY_IO_READABLE), Qnil);
+ return rb_fiber_scheduler_io_wait(scheduler, io, RB_UINT2NUM(RUBY_IO_READABLE), Qnil);
}
VALUE
-rb_scheduler_io_wait_writable(VALUE scheduler, VALUE io)
-{
- return rb_scheduler_io_wait(scheduler, io, RB_UINT2NUM(RUBY_IO_WRITABLE), Qnil);
-}
-
-int
-rb_scheduler_supports_io_read(VALUE scheduler)
+rb_fiber_scheduler_io_wait_writable(VALUE scheduler, VALUE io)
{
- return rb_respond_to(scheduler, id_io_read);
+ return rb_fiber_scheduler_io_wait(scheduler, io, RB_UINT2NUM(RUBY_IO_WRITABLE), Qnil);
}
VALUE
-rb_scheduler_io_read(VALUE scheduler, VALUE io, VALUE buffer, size_t offset, size_t length)
+rb_fiber_scheduler_io_read(VALUE scheduler, VALUE io, VALUE buffer, size_t offset, size_t length)
{
- return rb_funcall(scheduler, id_io_read, 4, io, buffer, SIZET2NUM(offset), SIZET2NUM(length));
-}
-
-int
-rb_scheduler_supports_io_write(VALUE scheduler)
-{
- return rb_respond_to(scheduler, id_io_write);
+ VALUE arguments[] = {
+ io, buffer, SIZET2NUM(offset), SIZET2NUM(length)
+ };
+
+ return rb_check_funcall(scheduler, id_io_read, 4, arguments);
}
VALUE
-rb_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_t offset, size_t length)
+rb_fiber_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_t offset, size_t length)
{
+ VALUE arguments[] = {
+ io, buffer, SIZET2NUM(offset), SIZET2NUM(length)
+ };
+
// We should ensure string has capacity to receive data, and then resize it afterwards.
- return rb_funcall(scheduler, id_io_write, 4, io, buffer, SIZET2NUM(offset), SIZET2NUM(length));
+ return rb_check_funcall(scheduler, id_io_write, 4, arguments);
}