@@ -1798,12 +1798,12 @@ rb_thread_mn_schedulable(VALUE thval)
17981798}
17991799
18001800VALUE
1801- rb_thread_io_blocking_call (rb_blocking_function_t * func , void * data1 , int fd , int events )
1801+ rb_thread_io_blocking_call (struct rb_io * io , rb_blocking_function_t * func , void * data1 , int events )
18021802{
18031803 rb_execution_context_t * volatile ec = GET_EC ();
18041804 rb_thread_t * volatile th = rb_ec_thread_ptr (ec );
18051805
1806- RUBY_DEBUG_LOG ("th:%u fd:%d ev:%d" , rb_th_serial (th ), fd , events );
1806+ RUBY_DEBUG_LOG ("th:%u fd:%d ev:%d" , rb_th_serial (th ), io -> fd , events );
18071807
18081808 struct waiting_fd waiting_fd ;
18091809 volatile VALUE val = Qundef ; /* shouldn't be used */
@@ -1812,6 +1812,8 @@ rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, in
18121812 volatile bool prev_mn_schedulable = th -> mn_schedulable ;
18131813 th -> mn_schedulable = thread_io_mn_schedulable (th , events , NULL );
18141814
1815+ int fd = io -> fd ;
1816+
18151817 // `errno` is only valid when there is an actual error - but we can't
18161818 // extract that from the return value of `func` alone, so we clear any
18171819 // prior `errno` value here so that we can later check if it was set by
@@ -1824,10 +1826,10 @@ rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, in
18241826 if ((state = EC_EXEC_TAG ()) == TAG_NONE ) {
18251827 volatile enum ruby_tag_type saved_state = state ; /* for BLOCKING_REGION */
18261828 retry :
1827- BLOCKING_REGION (waiting_fd . th , {
1829+ BLOCKING_REGION (th , {
18281830 val = func (data1 );
18291831 saved_errno = errno ;
1830- }, ubf_select , waiting_fd . th , FALSE);
1832+ }, ubf_select , th , FALSE);
18311833
18321834 th = rb_ec_thread_ptr (ec );
18331835 if (events &&
@@ -1866,9 +1868,9 @@ rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, in
18661868}
18671869
18681870VALUE
1869- rb_thread_io_blocking_region (rb_blocking_function_t * func , void * data1 , int fd )
1871+ rb_thread_io_blocking_region (struct rb_io * io , rb_blocking_function_t * func , void * data1 )
18701872{
1871- return rb_thread_io_blocking_call (func , data1 , fd , 0 );
1873+ return rb_thread_io_blocking_call (io , func , data1 , 0 );
18721874}
18731875
18741876/*
@@ -4398,8 +4400,8 @@ wait_for_single_fd_blocking_region(rb_thread_t *th, struct pollfd *fds, nfds_t n
43984400/*
43994401 * returns a mask of events
44004402 */
4401- int
4402- rb_thread_wait_for_single_fd ( int fd , int events , struct timeval * timeout )
4403+ static int
4404+ thread_io_wait ( struct rb_io * io , int fd , int events , struct timeval * timeout )
44034405{
44044406 struct pollfd fds [1 ] = {{
44054407 .fd = fd ,
@@ -4533,15 +4535,14 @@ init_set_fd(int fd, rb_fdset_t *fds)
45334535 return fds ;
45344536}
45354537
4536- int
4537- rb_thread_wait_for_single_fd ( int fd , int events , struct timeval * timeout )
4538+ static int
4539+ thread_io_wait ( struct rb_io * io , int fd , int events , struct timeval * timeout )
45384540{
45394541 rb_fdset_t rfds , wfds , efds ;
45404542 struct select_args args ;
45414543 int r ;
45424544 VALUE ptr = (VALUE )& args ;
4543- rb_execution_context_t * ec = GET_EC ();
4544- rb_thread_t * th = rb_ec_thread_ptr (ec );
4545+ rb_thread_t * th = GET_THREAD ();
45454546
45464547 args .as .fd = fd ;
45474548 args .read = (events & RB_WAITFD_IN ) ? init_set_fd (fd , & rfds ) : NULL ;
@@ -4558,6 +4559,18 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
45584559}
45594560#endif /* ! USE_POLL */
45604561
4562+ int
4563+ rb_thread_wait_for_single_fd (int fd , int events , struct timeval * timeout )
4564+ {
4565+ return thread_io_wait (NULL , fd , events , timeout );
4566+ }
4567+
4568+ int
4569+ rb_thread_io_wait (struct rb_io * io , int events , struct timeval * timeout )
4570+ {
4571+ return thread_io_wait (io , io -> fd , events , timeout );
4572+ }
4573+
45614574/*
45624575 * for GC
45634576 */
0 commit comments