1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Define functions using rb_wait_for_single_fd [Bug #18046]

This commit is contained in:
Nobuyoshi Nakada 2021-08-01 06:49:07 +09:00 committed by GitHub
parent 242f024bcb
commit 3b52230452
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2021-08-01 06:49:36 +09:00
Merged: https://github.com/ruby/ruby/pull/4696

Merged-By: nobu <nobu@ruby-lang.org>
3 changed files with 30 additions and 2 deletions

View file

@ -7,8 +7,24 @@ thread_fd_close(VALUE ign, VALUE fd)
return Qnil;
}
static VALUE
thread_fd_wait(VALUE ign, VALUE fd)
{
int ret = rb_thread_wait_fd(NUM2INT(fd));
return INT2NUM(ret);
}
static VALUE
thread_fd_writable(VALUE ign, VALUE fd)
{
int ret = rb_thread_fd_writable(NUM2INT(fd));
return INT2NUM(ret);
}
void
Init_thread_fd(void)
{
rb_define_singleton_method(rb_cIO, "thread_fd_close", thread_fd_close, 1);
rb_define_singleton_method(rb_cIO, "thread_fd_wait", thread_fd_wait, 1);
rb_define_singleton_method(rb_cIO, "thread_fd_writable", thread_fd_writable, 1);
}

View file

@ -31,8 +31,8 @@ struct timeval;
/* thread.c */
void rb_thread_schedule(void);
#define rb_thread_wait_fd(fd) rb_wait_for_single_fd((fd), RUBY_IO_READABLE, NULL)
#define rb_thread_fd_writable(fd) rb_wait_for_single_fd((fd), RUBY_IO_WRITABLE, NULL)
int rb_thread_wait_fd(int);
int rb_thread_fd_writable(int);
void rb_thread_fd_close(int);
int rb_thread_alone(void);
void rb_thread_sleep(int);

12
io.c
View file

@ -1408,6 +1408,18 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout)
return io_wait_for_single_fd(fd, events, timeout);
}
int
rb_thread_wait_fd(int fd)
{
return rb_wait_for_single_fd(fd, RUBY_IO_READABLE, NULL);
}
int
rb_thread_fd_writable(int fd)
{
return rb_wait_for_single_fd(fd, RUBY_IO_WRITABLE, NULL);
}
VALUE rb_io_maybe_wait(int error, VALUE io, VALUE events, VALUE timeout)
{
switch (error) {