ruby-changes:62921
From: Samuel <ko1@a...>
Date: Mon, 14 Sep 2020 13:44:33 +0900 (JST)
Subject: [ruby-changes:62921] 9e0a48c7a3 (master): Prefer `rb_thread_current_scheduler`.
https://git.ruby-lang.org/ruby.git/commit/?id=9e0a48c7a3 From 9e0a48c7a31ecd39be0596d0517b9d521ae75282 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Sat, 5 Sep 2020 14:30:21 +1200 Subject: Prefer `rb_thread_current_scheduler`. diff --git a/io.c b/io.c index f73a508..ed808d0 100644 --- a/io.c +++ b/io.c @@ -1314,7 +1314,7 @@ rb_io_from_fd(int f) https://github.com/ruby/ruby/blob/trunk/io.c#L1314 int rb_io_wait_readable(int f) { - VALUE scheduler = rb_thread_scheduler_if_nonblocking(rb_thread_current()); + VALUE scheduler = rb_thread_current_scheduler(); if (scheduler != Qnil) { return RTEST( rb_scheduler_io_wait_readable(scheduler, rb_io_from_fd(f)) @@ -1345,7 +1345,7 @@ rb_io_wait_readable(int f) https://github.com/ruby/ruby/blob/trunk/io.c#L1345 int rb_io_wait_writable(int f) { - VALUE scheduler = rb_thread_scheduler_if_nonblocking(rb_thread_current()); + VALUE scheduler = rb_thread_current_scheduler(); if (scheduler != Qnil) { return RTEST( rb_scheduler_io_wait_writable(scheduler, rb_io_from_fd(f)) @@ -1545,6 +1545,18 @@ io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync) https://github.com/ruby/ruby/blob/trunk/io.c#L1545 rb_thread_check_ints(); if ((n = len) <= 0) return n; + + VALUE scheduler = rb_thread_current_scheduler(); + if (scheduler != Qnil && rb_scheduler_supports_io_write(scheduler)) { + ssize_t length = RB_NUM2SSIZE( + rb_scheduler_io_write(scheduler, fptr->self, str, offset, len) + ); + + if (length < 0) rb_sys_fail_path(fptr->pathv); + + return length; + } + if (fptr->wbuf.ptr == NULL && !(!nosync && (fptr->mode & FMODE_SYNC))) { fptr->wbuf.off = 0; fptr->wbuf.len = 0; @@ -2621,9 +2633,15 @@ io_fread(VALUE str, long offset, long size, rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L2633 { VALUE scheduler = rb_thread_current_scheduler(); if (scheduler != Qnil && rb_scheduler_supports_io_read(scheduler)) { - return rb_scheduler_io_read(scheduler, fptr->self, str, offset, size); + ssize_t length = RB_NUM2SSIZE( + rb_scheduler_io_read(scheduler, fptr->self, str, offset, size) + ); + + if (length < 0) rb_sys_fail_path(fptr->pathv); + + return length; } - + long len; struct bufread_arg arg; diff --git a/process.c b/process.c index 317f7ff..8abb3ea 100644 --- a/process.c +++ b/process.c @@ -4926,7 +4926,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/process.c#L4926 rb_f_sleep(int argc, VALUE *argv, VALUE _) { time_t beg = time(0); - VALUE scheduler = rb_thread_scheduler_if_nonblocking(rb_thread_current()); + VALUE scheduler = rb_thread_current_scheduler(); if (scheduler != Qnil) { rb_scheduler_kernel_sleepv(scheduler, argc, argv); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/