diff options
-rw-r--r-- | ext/-test-/thread_fd/thread_fd.c | 16 | ||||
-rw-r--r-- | include/ruby/internal/intern/thread.h | 4 | ||||
-rw-r--r-- | io.c | 12 |
3 files changed, 30 insertions, 2 deletions
diff --git a/ext/-test-/thread_fd/thread_fd.c b/ext/-test-/thread_fd/thread_fd.c index 3d3ec8a2e0..042b799dc8 100644 --- a/ext/-test-/thread_fd/thread_fd.c +++ b/ext/-test-/thread_fd/thread_fd.c @@ -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); } diff --git a/include/ruby/internal/intern/thread.h b/include/ruby/internal/intern/thread.h index dd591474ce..7c656a628c 100644 --- a/include/ruby/internal/intern/thread.h +++ b/include/ruby/internal/intern/thread.h @@ -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); @@ -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) { |