mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Prefer rb_thread_current_scheduler
.
This commit is contained in:
parent
701dcbb3ca
commit
9e0a48c7a3
Notes:
git
2020-09-14 13:44:37 +09:00
2 changed files with 23 additions and 5 deletions
26
io.c
26
io.c
|
@ -1314,7 +1314,7 @@ rb_io_from_fd(int f)
|
||||||
int
|
int
|
||||||
rb_io_wait_readable(int f)
|
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) {
|
if (scheduler != Qnil) {
|
||||||
return RTEST(
|
return RTEST(
|
||||||
rb_scheduler_io_wait_readable(scheduler, rb_io_from_fd(f))
|
rb_scheduler_io_wait_readable(scheduler, rb_io_from_fd(f))
|
||||||
|
@ -1345,7 +1345,7 @@ rb_io_wait_readable(int f)
|
||||||
int
|
int
|
||||||
rb_io_wait_writable(int f)
|
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) {
|
if (scheduler != Qnil) {
|
||||||
return RTEST(
|
return RTEST(
|
||||||
rb_scheduler_io_wait_writable(scheduler, rb_io_from_fd(f))
|
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)
|
||||||
rb_thread_check_ints();
|
rb_thread_check_ints();
|
||||||
|
|
||||||
if ((n = len) <= 0) return n;
|
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))) {
|
if (fptr->wbuf.ptr == NULL && !(!nosync && (fptr->mode & FMODE_SYNC))) {
|
||||||
fptr->wbuf.off = 0;
|
fptr->wbuf.off = 0;
|
||||||
fptr->wbuf.len = 0;
|
fptr->wbuf.len = 0;
|
||||||
|
@ -2621,9 +2633,15 @@ io_fread(VALUE str, long offset, long size, rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
VALUE scheduler = rb_thread_current_scheduler();
|
VALUE scheduler = rb_thread_current_scheduler();
|
||||||
if (scheduler != Qnil && rb_scheduler_supports_io_read(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;
|
long len;
|
||||||
struct bufread_arg arg;
|
struct bufread_arg arg;
|
||||||
|
|
||||||
|
|
|
@ -4926,7 +4926,7 @@ static VALUE
|
||||||
rb_f_sleep(int argc, VALUE *argv, VALUE _)
|
rb_f_sleep(int argc, VALUE *argv, VALUE _)
|
||||||
{
|
{
|
||||||
time_t beg = time(0);
|
time_t beg = time(0);
|
||||||
VALUE scheduler = rb_thread_scheduler_if_nonblocking(rb_thread_current());
|
VALUE scheduler = rb_thread_current_scheduler();
|
||||||
|
|
||||||
if (scheduler != Qnil) {
|
if (scheduler != Qnil) {
|
||||||
rb_scheduler_kernel_sleepv(scheduler, argc, argv);
|
rb_scheduler_kernel_sleepv(scheduler, argc, argv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue