Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define IO_WITHOUT_GVL macro #9677

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ opendir_without_gvl(const char *path)

u.in = path;

return rb_thread_call_without_gvl(nogvl_opendir, u.out, RUBY_UBF_IO, 0);
return IO_WITHOUT_GVL(nogvl_opendir, u.out);
}
else
return opendir(path);
Expand Down Expand Up @@ -1096,8 +1096,7 @@ chdir_path(VALUE path, bool yield_path)
}
else {
char *p = RSTRING_PTR(path);
int r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_chdir, p,
RUBY_UBF_IO, 0);
int r = IO_WITHOUT_GVL_INT(nogvl_chdir, p);
if (r < 0)
rb_sys_fail_path(path);
}
Expand Down Expand Up @@ -1309,8 +1308,7 @@ dir_s_fchdir(VALUE klass, VALUE fd_value)
return rb_ensure(fchdir_yield, (VALUE)&args, fchdir_restore, (VALUE)&args);
}
else {
int r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_fchdir, &fd,
RUBY_UBF_IO, 0);
int r = IO_WITHOUT_GVL_INT(nogvl_fchdir, &fd);
if (r < 0)
rb_sys_fail("fchdir");
}
Expand Down Expand Up @@ -1506,7 +1504,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)

path = check_dirname(path);
m.path = RSTRING_PTR(path);
r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_mkdir, &m, RUBY_UBF_IO, 0);
r = IO_WITHOUT_GVL_INT(nogvl_mkdir, &m);
if (r < 0)
rb_sys_fail_path(path);

Expand Down Expand Up @@ -1539,7 +1537,7 @@ dir_s_rmdir(VALUE obj, VALUE dir)

dir = check_dirname(dir);
p = RSTRING_PTR(dir);
r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_rmdir, (void *)p, RUBY_UBF_IO, 0);
r = IO_WITHOUT_GVL_INT(nogvl_rmdir, (void *)p);
if (r < 0)
rb_sys_fail_path(dir);

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

if (vm_initialized)
return rb_thread_call_without_gvl(nogvl_opendir_at, &oaa, RUBY_UBF_IO, 0);
return IO_WITHOUT_GVL(nogvl_opendir_at, &oaa);
else
return nogvl_opendir_at(&oaa);
}
Expand Down Expand Up @@ -3618,8 +3616,7 @@ rb_dir_s_empty_p(VALUE obj, VALUE dirname)
}
#endif

result = (VALUE)rb_thread_call_without_gvl(nogvl_dir_empty_p, (void *)path,
RUBY_UBF_IO, 0);
result = (VALUE)IO_WITHOUT_GVL(nogvl_dir_empty_p, (void *)path);
if (FIXNUM_P(result)) {
rb_syserr_fail_path((int)FIX2LONG(result), orig);
}
Expand Down
28 changes: 10 additions & 18 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
aa->fn[aa->i].path = path;
}

rb_thread_call_without_gvl(no_gvl_apply2files, aa, RUBY_UBF_IO, 0);
IO_WITHOUT_GVL(no_gvl_apply2files, aa);
if (aa->errnum) {
#ifdef UTIME_EINVAL
if (func == utime_internal) {
Expand Down Expand Up @@ -1168,8 +1168,7 @@ stat_without_gvl(const char *path, struct stat *st)
data.file.path = path;
data.st = st;

return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_stat, &data,
RUBY_UBF_IO, NULL);
return IO_WITHOUT_GVL_INT(no_gvl_stat, &data);
}

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

/* call statx(2) with pathname */
return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_statx, &data,
RUBY_UBF_IO, NULL);
return IO_WITHOUT_GVL_INT(no_gvl_statx, &data);
}

static int
Expand Down Expand Up @@ -1382,8 +1380,7 @@ lstat_without_gvl(const char *path, struct stat *st)
data.file.path = path;
data.st = st;

return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_lstat, &data,
RUBY_UBF_IO, NULL);
return IO_WITHOUT_GVL_INT(no_gvl_lstat, &data);
}
#endif /* HAVE_LSTAT */

Expand Down Expand Up @@ -1557,8 +1554,7 @@ rb_eaccess(VALUE fname, int mode)
aa.path = StringValueCStr(fname);
aa.mode = mode;

return (int)(VALUE)rb_thread_call_without_gvl(nogvl_eaccess, &aa,
RUBY_UBF_IO, 0);
return IO_WITHOUT_GVL_INT(nogvl_eaccess, &aa);
}

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

return (int)(VALUE)rb_thread_call_without_gvl(nogvl_access, &aa,
RUBY_UBF_IO, 0);
return IO_WITHOUT_GVL_INT(nogvl_access, &aa);
}

/*
Expand Down Expand Up @@ -3140,8 +3135,7 @@ readlink_without_gvl(VALUE path, VALUE buf, size_t size)
ra.buf = RSTRING_PTR(buf);
ra.size = size;

return (ssize_t)rb_thread_call_without_gvl(nogvl_readlink, &ra,
RUBY_UBF_IO, 0);
return (ssize_t)IO_WITHOUT_GVL(nogvl_readlink, &ra);
}

VALUE
Expand Down Expand Up @@ -3242,8 +3236,7 @@ rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
#if defined __CYGWIN__
errno = 0;
#endif
if ((int)(VALUE)rb_thread_call_without_gvl(no_gvl_rename, &ra,
RUBY_UBF_IO, 0) < 0) {
if (IO_WITHOUT_GVL_INT(no_gvl_rename, &ra) < 0) {
int e = errno;
#if defined DOSISH
switch (e) {
Expand Down Expand Up @@ -5128,8 +5121,7 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
path = rb_str_encode_ospath(path);
ta.path = StringValueCStr(path);

r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_truncate, &ta,
RUBY_UBF_IO, NULL);
r = IO_WITHOUT_GVL_INT(nogvl_truncate, &ta);
if (r < 0)
rb_sys_fail_path(path);
return INT2FIX(0);
Expand Down Expand Up @@ -6201,7 +6193,7 @@ rb_file_s_mkfifo(int argc, VALUE *argv, VALUE _)
FilePathValue(path);
path = rb_str_encode_ospath(path);
ma.path = RSTRING_PTR(path);
if (rb_thread_call_without_gvl(nogvl_mkfifo, &ma, RUBY_UBF_IO, 0)) {
if (IO_WITHOUT_GVL(nogvl_mkfifo, &ma)) {
rb_sys_fail_path(path);
}
return INT2FIX(0);
Expand Down
3 changes: 3 additions & 0 deletions internal/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ struct rb_io;

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

#define IO_WITHOUT_GVL(func, arg) rb_thread_call_without_gvl(func, arg, RUBY_UBF_IO, 0)
#define IO_WITHOUT_GVL_INT(func, arg) (int)(VALUE)IO_WITHOUT_GVL(func, arg)

/** Ruby's IO, metadata and buffers. */
struct rb_io {

Expand Down
9 changes: 4 additions & 5 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -5429,7 +5429,7 @@ maygvl_close(int fd, int keepgvl)
* close() may block for certain file types (NFS, SO_LINGER sockets,
* inotify), so let other threads run.
*/
return (int)(intptr_t)rb_thread_call_without_gvl(nogvl_close, &fd, RUBY_UBF_IO, 0);
return IO_WITHOUT_GVL_INT(nogvl_close, &fd);
}

static void*
Expand All @@ -5446,7 +5446,7 @@ maygvl_fclose(FILE *file, int keepgvl)
if (keepgvl)
return fclose(file);

return (int)(intptr_t)rb_thread_call_without_gvl(nogvl_fclose, file, RUBY_UBF_IO, 0);
return IO_WITHOUT_GVL_INT(nogvl_fclose, file);
}

static void free_io_buffer(rb_io_buffer_t *buf);
Expand Down Expand Up @@ -6967,8 +6967,7 @@ sysopen_func(void *ptr)
static inline int
rb_sysopen_internal(struct sysopen_struct *data)
{
int fd;
fd = (int)(VALUE)rb_thread_call_without_gvl(sysopen_func, data, RUBY_UBF_IO, 0);
int fd = IO_WITHOUT_GVL_INT(sysopen_func, data);
if (0 <= fd)
rb_update_max_fd(fd);
return fd;
Expand Down Expand Up @@ -13260,7 +13259,7 @@ copy_stream_body(VALUE arg)
return copy_stream_fallback(stp);
}

rb_thread_call_without_gvl(nogvl_copy_stream_func, (void*)stp, RUBY_UBF_IO, 0);
IO_WITHOUT_GVL(nogvl_copy_stream_func, stp);
return Qnil;
}

Expand Down