Skip to content

Commit d86c4e5

Browse files
committed
Define IO_WITHOUT_GVL macro
1 parent 0f417d6 commit d86c4e5

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

dir.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ opendir_without_gvl(const char *path)
519519

520520
u.in = path;
521521

522-
return rb_thread_call_without_gvl(nogvl_opendir, u.out, RUBY_UBF_IO, 0);
522+
return IO_WITHOUT_GVL(nogvl_opendir, u.out);
523523
}
524524
else
525525
return opendir(path);
@@ -1096,8 +1096,7 @@ chdir_path(VALUE path, bool yield_path)
10961096
}
10971097
else {
10981098
char *p = RSTRING_PTR(path);
1099-
int r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_chdir, p,
1100-
RUBY_UBF_IO, 0);
1099+
int r = IO_WITHOUT_GVL_INT(nogvl_chdir, p);
11011100
if (r < 0)
11021101
rb_sys_fail_path(path);
11031102
}
@@ -1309,8 +1308,7 @@ dir_s_fchdir(VALUE klass, VALUE fd_value)
13091308
return rb_ensure(fchdir_yield, (VALUE)&args, fchdir_restore, (VALUE)&args);
13101309
}
13111310
else {
1312-
int r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_fchdir, &fd,
1313-
RUBY_UBF_IO, 0);
1311+
int r = IO_WITHOUT_GVL_INT(nogvl_fchdir, &fd);
13141312
if (r < 0)
13151313
rb_sys_fail("fchdir");
13161314
}
@@ -1506,7 +1504,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
15061504

15071505
path = check_dirname(path);
15081506
m.path = RSTRING_PTR(path);
1509-
r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_mkdir, &m, RUBY_UBF_IO, 0);
1507+
r = IO_WITHOUT_GVL_INT(nogvl_mkdir, &m);
15101508
if (r < 0)
15111509
rb_sys_fail_path(path);
15121510

@@ -1539,7 +1537,7 @@ dir_s_rmdir(VALUE obj, VALUE dir)
15391537

15401538
dir = check_dirname(dir);
15411539
p = RSTRING_PTR(dir);
1542-
r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_rmdir, (void *)p, RUBY_UBF_IO, 0);
1540+
r = IO_WITHOUT_GVL_INT(nogvl_rmdir, (void *)p);
15431541
if (r < 0)
15441542
rb_sys_fail_path(dir);
15451543

@@ -1758,7 +1756,7 @@ opendir_at(int basefd, const char *path)
17581756
oaa.path = path;
17591757

17601758
if (vm_initialized)
1761-
return rb_thread_call_without_gvl(nogvl_opendir_at, &oaa, RUBY_UBF_IO, 0);
1759+
return IO_WITHOUT_GVL(nogvl_opendir_at, &oaa);
17621760
else
17631761
return nogvl_opendir_at(&oaa);
17641762
}
@@ -3618,8 +3616,7 @@ rb_dir_s_empty_p(VALUE obj, VALUE dirname)
36183616
}
36193617
#endif
36203618

3621-
result = (VALUE)rb_thread_call_without_gvl(nogvl_dir_empty_p, (void *)path,
3622-
RUBY_UBF_IO, 0);
3619+
result = (VALUE)IO_WITHOUT_GVL(nogvl_dir_empty_p, (void *)path);
36233620
if (FIXNUM_P(result)) {
36243621
rb_syserr_fail_path((int)FIX2LONG(result), orig);
36253622
}

file.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
468468
aa->fn[aa->i].path = path;
469469
}
470470

471-
rb_thread_call_without_gvl(no_gvl_apply2files, aa, RUBY_UBF_IO, 0);
471+
IO_WITHOUT_GVL(no_gvl_apply2files, aa);
472472
if (aa->errnum) {
473473
#ifdef UTIME_EINVAL
474474
if (func == utime_internal) {
@@ -1168,8 +1168,7 @@ stat_without_gvl(const char *path, struct stat *st)
11681168
data.file.path = path;
11691169
data.st = st;
11701170

1171-
return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_stat, &data,
1172-
RUBY_UBF_IO, NULL);
1171+
return IO_WITHOUT_GVL_INT(no_gvl_stat, &data);
11731172
}
11741173

11751174
#if !defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC) && \
@@ -1219,8 +1218,7 @@ statx_without_gvl(const char *path, struct statx *stx, unsigned int mask)
12191218
no_gvl_statx_data data = {stx, AT_FDCWD, path, 0, mask};
12201219

12211220
/* call statx(2) with pathname */
1222-
return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_statx, &data,
1223-
RUBY_UBF_IO, NULL);
1221+
return IO_WITHOUT_GVL_INT(no_gvl_statx, &data);
12241222
}
12251223

12261224
static int
@@ -1382,8 +1380,7 @@ lstat_without_gvl(const char *path, struct stat *st)
13821380
data.file.path = path;
13831381
data.st = st;
13841382

1385-
return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_lstat, &data,
1386-
RUBY_UBF_IO, NULL);
1383+
return IO_WITHOUT_GVL_INT(no_gvl_lstat, &data);
13871384
}
13881385
#endif /* HAVE_LSTAT */
13891386

@@ -1557,8 +1554,7 @@ rb_eaccess(VALUE fname, int mode)
15571554
aa.path = StringValueCStr(fname);
15581555
aa.mode = mode;
15591556

1560-
return (int)(VALUE)rb_thread_call_without_gvl(nogvl_eaccess, &aa,
1561-
RUBY_UBF_IO, 0);
1557+
return IO_WITHOUT_GVL_INT(nogvl_eaccess, &aa);
15621558
}
15631559

15641560
static void *
@@ -1579,8 +1575,7 @@ rb_access(VALUE fname, int mode)
15791575
aa.path = StringValueCStr(fname);
15801576
aa.mode = mode;
15811577

1582-
return (int)(VALUE)rb_thread_call_without_gvl(nogvl_access, &aa,
1583-
RUBY_UBF_IO, 0);
1578+
return IO_WITHOUT_GVL_INT(nogvl_access, &aa);
15841579
}
15851580

15861581
/*
@@ -3140,8 +3135,7 @@ readlink_without_gvl(VALUE path, VALUE buf, size_t size)
31403135
ra.buf = RSTRING_PTR(buf);
31413136
ra.size = size;
31423137

3143-
return (ssize_t)rb_thread_call_without_gvl(nogvl_readlink, &ra,
3144-
RUBY_UBF_IO, 0);
3138+
return (ssize_t)IO_WITHOUT_GVL(nogvl_readlink, &ra);
31453139
}
31463140

31473141
VALUE
@@ -3242,8 +3236,7 @@ rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
32423236
#if defined __CYGWIN__
32433237
errno = 0;
32443238
#endif
3245-
if ((int)(VALUE)rb_thread_call_without_gvl(no_gvl_rename, &ra,
3246-
RUBY_UBF_IO, 0) < 0) {
3239+
if (IO_WITHOUT_GVL_INT(no_gvl_rename, &ra) < 0) {
32473240
int e = errno;
32483241
#if defined DOSISH
32493242
switch (e) {
@@ -5128,8 +5121,7 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
51285121
path = rb_str_encode_ospath(path);
51295122
ta.path = StringValueCStr(path);
51305123

5131-
r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_truncate, &ta,
5132-
RUBY_UBF_IO, NULL);
5124+
r = IO_WITHOUT_GVL_INT(nogvl_truncate, &ta);
51335125
if (r < 0)
51345126
rb_sys_fail_path(path);
51355127
return INT2FIX(0);
@@ -6201,7 +6193,7 @@ rb_file_s_mkfifo(int argc, VALUE *argv, VALUE _)
62016193
FilePathValue(path);
62026194
path = rb_str_encode_ospath(path);
62036195
ma.path = RSTRING_PTR(path);
6204-
if (rb_thread_call_without_gvl(nogvl_mkfifo, &ma, RUBY_UBF_IO, 0)) {
6196+
if (IO_WITHOUT_GVL(nogvl_mkfifo, &ma)) {
62056197
rb_sys_fail_path(path);
62066198
}
62076199
return INT2FIX(0);

internal/io.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ struct rb_io;
1515

1616
#include "ruby/io.h" /* for rb_io_t */
1717

18+
#define IO_WITHOUT_GVL(func, arg) rb_thread_call_without_gvl(func, arg, RUBY_UBF_IO, 0)
19+
#define IO_WITHOUT_GVL_INT(func, arg) (int)(VALUE)IO_WITHOUT_GVL(func, arg)
20+
1821
/** Ruby's IO, metadata and buffers. */
1922
struct rb_io {
2023

io.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5429,7 +5429,7 @@ maygvl_close(int fd, int keepgvl)
54295429
* close() may block for certain file types (NFS, SO_LINGER sockets,
54305430
* inotify), so let other threads run.
54315431
*/
5432-
return (int)(intptr_t)rb_thread_call_without_gvl(nogvl_close, &fd, RUBY_UBF_IO, 0);
5432+
return IO_WITHOUT_GVL_INT(nogvl_close, &fd);
54335433
}
54345434

54355435
static void*
@@ -5446,7 +5446,7 @@ maygvl_fclose(FILE *file, int keepgvl)
54465446
if (keepgvl)
54475447
return fclose(file);
54485448

5449-
return (int)(intptr_t)rb_thread_call_without_gvl(nogvl_fclose, file, RUBY_UBF_IO, 0);
5449+
return IO_WITHOUT_GVL_INT(nogvl_fclose, file);
54505450
}
54515451

54525452
static void free_io_buffer(rb_io_buffer_t *buf);
@@ -6967,8 +6967,7 @@ sysopen_func(void *ptr)
69676967
static inline int
69686968
rb_sysopen_internal(struct sysopen_struct *data)
69696969
{
6970-
int fd;
6971-
fd = (int)(VALUE)rb_thread_call_without_gvl(sysopen_func, data, RUBY_UBF_IO, 0);
6970+
int fd = IO_WITHOUT_GVL_INT(sysopen_func, data);
69726971
if (0 <= fd)
69736972
rb_update_max_fd(fd);
69746973
return fd;
@@ -13260,7 +13259,7 @@ copy_stream_body(VALUE arg)
1326013259
return copy_stream_fallback(stp);
1326113260
}
1326213261

13263-
rb_thread_call_without_gvl(nogvl_copy_stream_func, (void*)stp, RUBY_UBF_IO, 0);
13262+
IO_WITHOUT_GVL(nogvl_copy_stream_func, stp);
1326413263
return Qnil;
1326513264
}
1326613265

0 commit comments

Comments
 (0)