[前][次][番号順一覧][スレッド一覧]

ruby-changes:48745

From: normal <ko1@a...>
Date: Mon, 20 Nov 2017 11:29:40 +0900 (JST)
Subject: [ruby-changes:48745] normal:r60861 (trunk): File.mkfifo releases GVL

normal	2017-11-20 11:29:35 +0900 (Mon, 20 Nov 2017)

  New Revision: 60861

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60861

  Log:
    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

  Modified files:
    trunk/file.c
Index: file.c
===================================================================
--- file.c	(revision 60860)
+++ file.c	(revision 60861)
@@ -5752,6 +5752,19 @@ rb_stat_sticky(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L5752
 #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 https://github.com/ruby/ruby/blob/trunk/file.c#L5779
 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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]