@@ -222,6 +222,17 @@ static VALUE sym_HOLE;
222
222
223
223
static VALUE prep_io (int fd , int fmode , VALUE klass , const char * path );
224
224
225
+ VALUE
226
+ rb_io_blocking_region_wait (struct rb_io * io , rb_blocking_function_t * function , void * argument , enum rb_io_event events )
227
+ {
228
+ return rb_thread_io_blocking_call (function , argument , io -> fd , events );
229
+ }
230
+
231
+ VALUE rb_io_blocking_region (struct rb_io * io , rb_blocking_function_t * function , void * argument )
232
+ {
233
+ return rb_io_blocking_region_wait (io , function , argument , 0 );
234
+ }
235
+
225
236
struct argf {
226
237
VALUE filename , current_file ;
227
238
long last_lineno ; /* $. */
@@ -1298,7 +1309,7 @@ rb_io_read_memory(rb_io_t *fptr, void *buf, size_t count)
1298
1309
iis .timeout = & timeout_storage ;
1299
1310
}
1300
1311
1301
- return (ssize_t )rb_thread_io_blocking_call ( internal_read_func , & iis , fptr -> fd , RB_WAITFD_IN );
1312
+ return (ssize_t )rb_io_blocking_region_wait ( fptr , internal_read_func , & iis , RUBY_IO_READABLE );
1302
1313
}
1303
1314
1304
1315
static ssize_t
@@ -1331,7 +1342,7 @@ rb_io_write_memory(rb_io_t *fptr, const void *buf, size_t count)
1331
1342
iis .timeout = & timeout_storage ;
1332
1343
}
1333
1344
1334
- return (ssize_t )rb_thread_io_blocking_call ( internal_write_func , & iis , fptr -> fd , RB_WAITFD_OUT );
1345
+ return (ssize_t )rb_io_blocking_region_wait ( fptr , internal_write_func , & iis , RUBY_IO_WRITABLE );
1335
1346
}
1336
1347
1337
1348
#ifdef HAVE_WRITEV
@@ -1368,7 +1379,7 @@ rb_writev_internal(rb_io_t *fptr, const struct iovec *iov, int iovcnt)
1368
1379
iis .timeout = & timeout_storage ;
1369
1380
}
1370
1381
1371
- return (ssize_t )rb_thread_io_blocking_call ( internal_writev_func , & iis , fptr -> fd , RB_WAITFD_OUT );
1382
+ return (ssize_t )rb_io_blocking_region_wait ( fptr , internal_writev_func , & iis , RUBY_IO_WRITABLE );
1372
1383
}
1373
1384
#endif
1374
1385
@@ -1398,7 +1409,7 @@ static VALUE
1398
1409
io_flush_buffer_async (VALUE arg )
1399
1410
{
1400
1411
rb_io_t * fptr = (rb_io_t * )arg ;
1401
- return rb_thread_io_blocking_call ( io_flush_buffer_sync , fptr , fptr -> fd , RB_WAITFD_OUT );
1412
+ return rb_io_blocking_region_wait ( fptr , io_flush_buffer_sync , fptr , RUBY_IO_WRITABLE );
1402
1413
}
1403
1414
1404
1415
static inline int
@@ -2788,8 +2799,10 @@ rb_io_fsync(VALUE io)
2788
2799
2789
2800
if (io_fflush (fptr ) < 0 )
2790
2801
rb_sys_fail_on_write (fptr );
2791
- if ((int )rb_thread_io_blocking_region (nogvl_fsync , fptr , fptr -> fd ) < 0 )
2802
+
2803
+ if ((int )rb_io_blocking_region (fptr , nogvl_fsync , fptr ))
2792
2804
rb_sys_fail_path (fptr -> pathv );
2805
+
2793
2806
return INT2FIX (0 );
2794
2807
}
2795
2808
#else
@@ -2838,7 +2851,7 @@ rb_io_fdatasync(VALUE io)
2838
2851
if (io_fflush (fptr ) < 0 )
2839
2852
rb_sys_fail_on_write (fptr );
2840
2853
2841
- if ((int )rb_thread_io_blocking_region ( nogvl_fdatasync , fptr , fptr -> fd ) == 0 )
2854
+ if ((int )rb_io_blocking_region ( fptr , nogvl_fdatasync , fptr ) == 0 )
2842
2855
return INT2FIX (0 );
2843
2856
2844
2857
/* fall back */
@@ -3423,10 +3436,10 @@ io_read_memory_call(VALUE arg)
3423
3436
}
3424
3437
3425
3438
if (iis -> nonblock ) {
3426
- return rb_thread_io_blocking_call ( internal_read_func , iis , iis -> fptr -> fd , 0 );
3439
+ return rb_io_blocking_region ( iis -> fptr , internal_read_func , iis );
3427
3440
}
3428
3441
else {
3429
- return rb_thread_io_blocking_call ( internal_read_func , iis , iis -> fptr -> fd , RB_WAITFD_IN );
3442
+ return rb_io_blocking_region_wait ( iis -> fptr , internal_read_func , iis , RUBY_IO_READABLE );
3430
3443
}
3431
3444
}
3432
3445
@@ -6099,7 +6112,7 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
6099
6112
}
6100
6113
6101
6114
struct prdwr_internal_arg {
6102
- VALUE io ;
6115
+ struct rb_io * io ;
6103
6116
int fd ;
6104
6117
void * buf ;
6105
6118
size_t count ;
@@ -6121,14 +6134,14 @@ pread_internal_call(VALUE _arg)
6121
6134
6122
6135
VALUE scheduler = rb_fiber_scheduler_current ();
6123
6136
if (scheduler != Qnil ) {
6124
- VALUE result = rb_fiber_scheduler_io_pread_memory (scheduler , arg -> io , arg -> offset , arg -> buf , arg -> count , 0 );
6137
+ VALUE result = rb_fiber_scheduler_io_pread_memory (scheduler , arg -> io -> self , arg -> offset , arg -> buf , arg -> count , 0 );
6125
6138
6126
6139
if (!UNDEF_P (result )) {
6127
6140
return rb_fiber_scheduler_io_result_apply (result );
6128
6141
}
6129
6142
}
6130
6143
6131
- return rb_thread_io_blocking_call ( internal_pread_func , arg , arg -> fd , RB_WAITFD_IN );
6144
+ return rb_io_blocking_region_wait ( arg -> io , internal_pread_func , arg , RUBY_IO_READABLE );
6132
6145
}
6133
6146
6134
6147
/*
@@ -6165,7 +6178,7 @@ rb_io_pread(int argc, VALUE *argv, VALUE io)
6165
6178
VALUE len , offset , str ;
6166
6179
rb_io_t * fptr ;
6167
6180
ssize_t n ;
6168
- struct prdwr_internal_arg arg = {. io = io } ;
6181
+ struct prdwr_internal_arg arg ;
6169
6182
int shrinkable ;
6170
6183
6171
6184
rb_scan_args (argc , argv , "21" , & len , & offset , & str );
@@ -6179,6 +6192,7 @@ rb_io_pread(int argc, VALUE *argv, VALUE io)
6179
6192
GetOpenFile (io , fptr );
6180
6193
rb_io_check_byte_readable (fptr );
6181
6194
6195
+ arg .io = fptr ;
6182
6196
arg .fd = fptr -> fd ;
6183
6197
rb_io_check_closed (fptr );
6184
6198
@@ -6203,7 +6217,7 @@ internal_pwrite_func(void *_arg)
6203
6217
6204
6218
VALUE scheduler = rb_fiber_scheduler_current ();
6205
6219
if (scheduler != Qnil ) {
6206
- VALUE result = rb_fiber_scheduler_io_pwrite_memory (scheduler , arg -> io , arg -> offset , arg -> buf , arg -> count , 0 );
6220
+ VALUE result = rb_fiber_scheduler_io_pwrite_memory (scheduler , arg -> io -> self , arg -> offset , arg -> buf , arg -> count , 0 );
6207
6221
6208
6222
if (!UNDEF_P (result )) {
6209
6223
return rb_fiber_scheduler_io_result_apply (result );
@@ -6244,7 +6258,7 @@ rb_io_pwrite(VALUE io, VALUE str, VALUE offset)
6244
6258
{
6245
6259
rb_io_t * fptr ;
6246
6260
ssize_t n ;
6247
- struct prdwr_internal_arg arg = {. io = io } ;
6261
+ struct prdwr_internal_arg arg ;
6248
6262
VALUE tmp ;
6249
6263
6250
6264
if (!RB_TYPE_P (str , T_STRING ))
@@ -6255,13 +6269,15 @@ rb_io_pwrite(VALUE io, VALUE str, VALUE offset)
6255
6269
io = GetWriteIO (io );
6256
6270
GetOpenFile (io , fptr );
6257
6271
rb_io_check_writable (fptr );
6272
+
6273
+ arg .io = fptr ;
6258
6274
arg .fd = fptr -> fd ;
6259
6275
6260
6276
tmp = rb_str_tmp_frozen_acquire (str );
6261
6277
arg .buf = RSTRING_PTR (tmp );
6262
6278
arg .count = (size_t )RSTRING_LEN (tmp );
6263
6279
6264
- n = (ssize_t )rb_thread_io_blocking_call ( internal_pwrite_func , & arg , fptr -> fd , RB_WAITFD_OUT );
6280
+ n = (ssize_t )rb_io_blocking_region_wait ( fptr , internal_pwrite_func , & arg , RUBY_IO_WRITABLE );
6265
6281
if (n < 0 ) rb_sys_fail_path (fptr -> pathv );
6266
6282
rb_str_tmp_frozen_release (str , tmp );
6267
6283
@@ -10806,7 +10822,7 @@ do_io_advise(rb_io_t *fptr, VALUE advice, rb_off_t offset, rb_off_t len)
10806
10822
ias .offset = offset ;
10807
10823
ias .len = len ;
10808
10824
10809
- rv = (int )rb_thread_io_blocking_region ( io_advise_internal , & ias , fptr -> fd );
10825
+ rv = (int )rb_io_blocking_region ( fptr , io_advise_internal , & ias );
10810
10826
if (rv && rv != ENOSYS ) {
10811
10827
/* posix_fadvise(2) doesn't set errno. On success it returns 0; otherwise
10812
10828
it returns the error code. */
@@ -11099,16 +11115,16 @@ nogvl_ioctl(void *ptr)
11099
11115
}
11100
11116
11101
11117
static int
11102
- do_ioctl (int fd , ioctl_req_t cmd , long narg )
11118
+ do_ioctl (struct rb_io * io , ioctl_req_t cmd , long narg )
11103
11119
{
11104
11120
int retval ;
11105
11121
struct ioctl_arg arg ;
11106
11122
11107
- arg .fd = fd ;
11123
+ arg .fd = io -> fd ;
11108
11124
arg .cmd = cmd ;
11109
11125
arg .narg = narg ;
11110
11126
11111
- retval = (int )rb_thread_io_blocking_region ( nogvl_ioctl , & arg , fd );
11127
+ retval = (int )rb_io_blocking_region ( io , nogvl_ioctl , & arg );
11112
11128
11113
11129
return retval ;
11114
11130
}
@@ -11371,7 +11387,7 @@ rb_ioctl(VALUE io, VALUE req, VALUE arg)
11371
11387
11372
11388
narg = setup_narg (cmd , & arg , ioctl_narg_len );
11373
11389
GetOpenFile (io , fptr );
11374
- retval = do_ioctl (fptr -> fd , cmd , narg );
11390
+ retval = do_ioctl (fptr , cmd , narg );
11375
11391
return finish_narg (retval , arg , fptr );
11376
11392
}
11377
11393
@@ -11425,16 +11441,16 @@ nogvl_fcntl(void *ptr)
11425
11441
}
11426
11442
11427
11443
static int
11428
- do_fcntl (int fd , int cmd , long narg )
11444
+ do_fcntl (struct rb_io * io , int cmd , long narg )
11429
11445
{
11430
11446
int retval ;
11431
11447
struct fcntl_arg arg ;
11432
11448
11433
- arg .fd = fd ;
11449
+ arg .fd = io -> fd ;
11434
11450
arg .cmd = cmd ;
11435
11451
arg .narg = narg ;
11436
11452
11437
- retval = (int )rb_thread_io_blocking_region ( nogvl_fcntl , & arg , fd );
11453
+ retval = (int )rb_io_blocking_region ( io , nogvl_fcntl , & arg );
11438
11454
if (retval != -1 ) {
11439
11455
switch (cmd ) {
11440
11456
#if defined(F_DUPFD )
@@ -11460,7 +11476,7 @@ rb_fcntl(VALUE io, VALUE req, VALUE arg)
11460
11476
11461
11477
narg = setup_narg (cmd , & arg , fcntl_narg_len );
11462
11478
GetOpenFile (io , fptr );
11463
- retval = do_fcntl (fptr -> fd , cmd , narg );
11479
+ retval = do_fcntl (fptr , cmd , narg );
11464
11480
return finish_narg (retval , arg , fptr );
11465
11481
}
11466
11482
0 commit comments