Skip to content

Commit f34ca0c

Browse files
committed
[GR-17457] Optimize rb_wait_for_single_fd() to call poll(2) more directly
PullRequest: truffleruby/4109
2 parents 68e4330 + 0258c5f commit f34ca0c

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

lib/truffle/truffle/cext.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,25 +1977,15 @@ def rb_thread_fd_writable(fd)
19771977
end
19781978

19791979
def rb_wait_for_single_fd(fd, events, tv_secs, tv_usecs)
1980-
io = IO.for_fd(fd)
1981-
io.autoclose = false
1982-
read = (events & RB_WAITFD_IN) != 0 ? [io] : nil
1983-
write = (events & RB_WAITFD_OUT) != 0 ? [io] : nil
1984-
error = (events & RB_WAITFD_PRI) != 0 ? [io] : nil
19851980
timeout = nil
19861981
if tv_secs >= 0 || tv_usecs >= 0
19871982
timeout = tv_secs + tv_usecs/1.0e6
19881983
end
1989-
r, w, e = Primitive.send_without_cext_lock(IO, :select, [read, write, error, *timeout], nil)
1990-
if Primitive.nil?(r) # timeout
1991-
0
1992-
else
1993-
result = 0
1994-
result |= RB_WAITFD_IN unless r.empty?
1995-
result |= RB_WAITFD_OUT unless w.empty?
1996-
result |= RB_WAITFD_PRI unless e.empty?
1997-
result
1998-
end
1984+
1985+
io = IO.for_fd(fd)
1986+
io.autoclose = false
1987+
returned_events = Primitive.send_without_cext_lock(Truffle::IOOperations, :poll, [io, events, timeout], nil)
1988+
returned_events & (RB_WAITFD_IN | RB_WAITFD_OUT | RB_WAITFD_PRI)
19991989
end
20001990

20011991
def rb_call_super(args)

0 commit comments

Comments
 (0)