1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

File.mkfifo releases GVL

mkfifo(3) is subject to the same problems as open(2) on slow
filesystems.  Release the GVL and let the rest of the VM run
while we call mkfifo.

* file.c (nogvl_mkfifo): new function
  (rb_file_s_mkfifo): release GVL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2017-11-20 02:29:35 +00:00
parent b1152fab0f
commit b7cbe4e2e3

21
file.c
View file

@ -5752,6 +5752,19 @@ rb_stat_sticky(VALUE obj)
#endif
#ifdef HAVE_MKFIFO
struct mkfifo_arg {
const char *path;
mode_t mode;
};
static void *
nogvl_mkfifo(void *ptr)
{
struct mkfifo_arg *ma = ptr;
return (void *)(VALUE)mkfifo(ma->path, ma->mode);
}
/*
* call-seq:
* File.mkfifo(file_name, mode=0666) => 0
@ -5766,16 +5779,18 @@ static VALUE
rb_file_s_mkfifo(int argc, VALUE *argv)
{
VALUE path;
mode_t mode = 0666;
struct mkfifo_arg ma;
ma.mode = 0666;
rb_check_arity(argc, 1, 2);
if (argc > 1) {
mode = NUM2MODET(argv[1]);
ma.mode = NUM2MODET(argv[1]);
}
path = argv[0];
FilePathValue(path);
path = rb_str_encode_ospath(path);
if (mkfifo(RSTRING_PTR(path), mode)) {
ma.path = RSTRING_PTR(path);
if (rb_thread_call_without_gvl(nogvl_mkfifo, &ma, RUBY_UBF_IO, 0)) {
rb_sys_fail_path(path);
}
return INT2FIX(0);