mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Introduce rb_io_blocking_region
which takes struct rb_io
argument. (#11795)
This does not change any actual behaviour, but provides a choke point for blocking IO operations. * Update `IO::Buffer` to use `rb_io_blocking_region`. * Update `File` to use `rb_io_blocking_region`. * Update `IO` to use `rb_io_blocking_region`.
This commit is contained in:
parent
e766cb3e57
commit
c50298d7d4
Notes:
git
2024-10-05 02:10:30 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
5 changed files with 69 additions and 46 deletions
24
file.c
24
file.c
|
@ -1145,14 +1145,14 @@ no_gvl_fstat(void *data)
|
|||
}
|
||||
|
||||
static int
|
||||
fstat_without_gvl(int fd, struct stat *st)
|
||||
fstat_without_gvl(rb_io_t *fptr, struct stat *st)
|
||||
{
|
||||
no_gvl_stat_data data;
|
||||
|
||||
data.file.fd = fd;
|
||||
data.file.fd = fptr->fd;
|
||||
data.st = st;
|
||||
|
||||
return (int)(VALUE)rb_thread_io_blocking_region(no_gvl_fstat, &data, fd);
|
||||
return (int)rb_io_blocking_region(fptr, no_gvl_fstat, &data);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
@ -1224,12 +1224,12 @@ statx_without_gvl(const char *path, struct statx *stx, unsigned int mask)
|
|||
}
|
||||
|
||||
static int
|
||||
fstatx_without_gvl(int fd, struct statx *stx, unsigned int mask)
|
||||
fstatx_without_gvl(rb_io_t *fptr, struct statx *stx, unsigned int mask)
|
||||
{
|
||||
no_gvl_statx_data data = {stx, fd, "", AT_EMPTY_PATH, mask};
|
||||
no_gvl_statx_data data = {stx, fptr->fd, "", AT_EMPTY_PATH, mask};
|
||||
|
||||
/* call statx(2) with fd */
|
||||
return (int)rb_thread_io_blocking_region(io_blocking_statx, &data, fd);
|
||||
return (int)rb_io_blocking_region(fptr, io_blocking_statx, &data);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1242,7 +1242,7 @@ rb_statx(VALUE file, struct statx *stx, unsigned int mask)
|
|||
if (!NIL_P(tmp)) {
|
||||
rb_io_t *fptr;
|
||||
GetOpenFile(tmp, fptr);
|
||||
result = fstatx_without_gvl(fptr->fd, stx, mask);
|
||||
result = fstatx_without_gvl(fptr, stx, mask);
|
||||
file = tmp;
|
||||
}
|
||||
else {
|
||||
|
@ -1283,7 +1283,7 @@ typedef struct statx statx_data;
|
|||
|
||||
#elif defined(HAVE_STAT_BIRTHTIME)
|
||||
# define statx_without_gvl(path, st, mask) stat_without_gvl(path, st)
|
||||
# define fstatx_without_gvl(fd, st, mask) fstat_without_gvl(fd, st)
|
||||
# define fstatx_without_gvl(fptr, st, mask) fstat_without_gvl(fptr, st)
|
||||
# define statx_birthtime(st, fname) stat_birthtime(st)
|
||||
# define statx_has_birthtime(st) 1
|
||||
# define rb_statx(file, st, mask) rb_stat(file, st)
|
||||
|
@ -1303,7 +1303,7 @@ rb_stat(VALUE file, struct stat *st)
|
|||
rb_io_t *fptr;
|
||||
|
||||
GetOpenFile(tmp, fptr);
|
||||
result = fstat_without_gvl(fptr->fd, st);
|
||||
result = fstat_without_gvl(fptr, st);
|
||||
file = tmp;
|
||||
}
|
||||
else {
|
||||
|
@ -2501,7 +2501,7 @@ rb_file_birthtime(VALUE obj)
|
|||
statx_data st;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
if (fstatx_without_gvl(fptr->fd, &st, STATX_BTIME) == -1) {
|
||||
if (fstatx_without_gvl(fptr, &st, STATX_BTIME) == -1) {
|
||||
rb_sys_fail_path(fptr->pathv);
|
||||
}
|
||||
return statx_birthtime(&st, fptr->pathv);
|
||||
|
@ -5280,7 +5280,7 @@ rb_file_truncate(VALUE obj, VALUE len)
|
|||
}
|
||||
rb_io_flush_raw(obj, 0);
|
||||
fa.fd = fptr->fd;
|
||||
if ((int)rb_thread_io_blocking_region(nogvl_ftruncate, &fa, fa.fd) < 0) {
|
||||
if ((int)rb_io_blocking_region(fptr, nogvl_ftruncate, &fa) < 0) {
|
||||
rb_sys_fail_path(fptr->pathv);
|
||||
}
|
||||
return INT2FIX(0);
|
||||
|
@ -5380,7 +5380,7 @@ rb_file_flock(VALUE obj, VALUE operation)
|
|||
if (fptr->mode & FMODE_WRITABLE) {
|
||||
rb_io_flush_raw(obj, 0);
|
||||
}
|
||||
while ((int)rb_thread_io_blocking_region(rb_thread_flock, op, fptr->fd) < 0) {
|
||||
while ((int)rb_io_blocking_region(fptr, rb_thread_flock, op) < 0) {
|
||||
int e = errno;
|
||||
switch (e) {
|
||||
case EAGAIN:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue