Define IO_WITHOUT_GVL
macro
This commit is contained in:
parent
0f417d640d
commit
d86c4e553e
17
dir.c
17
dir.c
@ -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);
|
||||
@ -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);
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
28
file.c
28
file.c
@ -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) {
|
||||
@ -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) && \
|
||||
@ -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
|
||||
@ -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 */
|
||||
|
||||
@ -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 *
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -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
|
||||
@ -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) {
|
||||
@ -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);
|
||||
@ -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);
|
||||
|
@ -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 {
|
||||
|
||||
|
9
io.c
9
io.c
@ -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*
|
||||
@ -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);
|
||||
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user