Project

General

Profile

Bug #13941 » 0001-Release-gvl-while-doing-f-stat.patch

Patch to the `file.c` - graywolf (Gray Wolf), 09/26/2017 12:10 AM

View differences:

file.c
#include "internal.h"
#include "ruby/io.h"
#include "ruby/util.h"
#include "ruby/thread.h"
#include "dln.h"
#include "encindex.h"
......
return str;
}
typedef struct no_gvl_fstat_data {
int fd;
struct stat * st;
int result;
} no_gvl_fstat_data;
static void * no_gvl_fstat(void * data)
{
((no_gvl_fstat_data *) data)->result = fstat(
((no_gvl_fstat_data *) data)->fd,
((no_gvl_fstat_data *) data)->st
);
return NULL;
}
typedef struct no_gvl_stat_data {
const char * path;
struct stat * st;
int result;
} no_gvl_stat_data;
static void * no_gvl_stat(void * data)
{
((no_gvl_stat_data *) data)->result = STAT(
((no_gvl_stat_data *) data)->path,
((no_gvl_stat_data *) data)->st
);
return NULL;
}
static int
rb_stat(VALUE file, struct stat *st)
{
VALUE tmp;
no_gvl_fstat_data fstat_data;
no_gvl_stat_data stat_data;
tmp = rb_check_convert_type_with_id(file, T_FILE, "IO", idTo_io);
if (!NIL_P(tmp)) {
rb_io_t *fptr;
GetOpenFile(tmp, fptr);
return fstat(fptr->fd, st);
fstat_data.fd = fptr->fd;
fstat_data.st = st;
rb_thread_call_without_gvl(
no_gvl_fstat,
(void *) &fstat_data,
RUBY_UBF_IO,
NULL
);
return fstat_data.result;
}
FilePathValue(file);
file = rb_str_encode_ospath(file);
return STAT(StringValueCStr(file), st);
stat_data.path = StringValueCStr(file);
stat_data.st = st;
rb_thread_call_without_gvl(
no_gvl_stat,
(void *) &stat_data,
RUBY_UBF_IO,
NULL
);
return stat_data.result;
}
#ifdef _WIN32
......
rb_define_method(rb_cStat, "setgid?", rb_stat_sgid, 0);
rb_define_method(rb_cStat, "sticky?", rb_stat_sticky, 0);
}
/* vim: set ts=8 sw=4 noexpandtab: */
(1-1/4)