[前][次][番号順一覧][スレッド一覧]

ruby-changes:67012

From: Nobuyoshi <ko1@a...>
Date: Sun, 1 Aug 2021 06:49:20 +0900 (JST)
Subject: [ruby-changes:67012] 3b52230452 (master): Define functions using rb_wait_for_single_fd [Bug #18046]

https://git.ruby-lang.org/ruby.git/commit/?id=3b52230452

From 3b52230452980f3afc6a7380276ea62f7c65e517 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 1 Aug 2021 06:49:07 +0900
Subject: Define functions using rb_wait_for_single_fd [Bug #18046]

---
 ext/-test-/thread_fd/thread_fd.c      | 16 ++++++++++++++++
 include/ruby/internal/intern/thread.h |  4 ++--
 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 3d3ec8a..042b799 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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/thread_fd/thread_fd.c#L7
     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 dd59147..7c656a6 100644
--- a/include/ruby/internal/intern/thread.h
+++ b/include/ruby/internal/intern/thread.h
@@ -31,8 +31,8 @@ struct timeval; https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/intern/thread.h#L31
 
 /* 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);
diff --git a/io.c b/io.c
index 2199c1a..16f2526 100644
--- a/io.c
+++ b/io.c
@@ -1408,6 +1408,18 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout) https://github.com/ruby/ruby/blob/trunk/io.c#L1408
     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) {
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]