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

ruby-changes:38806

From: nobu <ko1@a...>
Date: Sun, 14 Jun 2015 17:21:12 +0900 (JST)
Subject: [ruby-changes:38806] nobu:r50887 (trunk): file.c: open without gvl

nobu	2015-06-14 17:20:43 +0900 (Sun, 14 Jun 2015)

  New Revision: 50887

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

  Log:
    file.c: open without gvl
    
    * file.c (rb_file_load_ok): try opening file without gvl not to
      lock entire process.  [Bug #11060]

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/file.c
    trunk/test/ruby/test_require.rb
    trunk/win32/file.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50886)
+++ ChangeLog	(revision 50887)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 14 17:20:40 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_file_load_ok): try opening file without gvl not to
+	  lock entire process.  [Bug #11060]
+
 Sun Jun 14 10:43:50 2015  NAKAMURA Usaku  <usa@r...>
 
 	* tool/runruby.rb: just remove the lines of RUBY_VERSION check and raise
Index: common.mk
===================================================================
--- common.mk	(revision 50886)
+++ common.mk	(revision 50887)
@@ -713,7 +713,8 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc https://github.com/ruby/ruby/blob/trunk/common.mk#L713
 
 win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}dln.h {$(VPATH)}dln_find.c \
   {$(VPATH)}internal.h $(RUBY_H_INCLUDES) $(PLATFORM_D)
-win32/file.$(OBJEXT): {$(VPATH)}win32/file.c $(RUBY_H_INCLUDES) $(PLATFORM_D)
+win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}thread.h \
+  $(RUBY_H_INCLUDES) $(PLATFORM_D)
 
 $(NEWLINE_C): $(srcdir)/enc/trans/newline.trans $(srcdir)/tool/transcode-tblgen.rb
 	$(Q) $(MAKEDIRS) $(@D)
@@ -1439,6 +1440,7 @@ file.$(OBJEXT): {$(VPATH)}missing.h https://github.com/ruby/ruby/blob/trunk/common.mk#L1440
 file.$(OBJEXT): {$(VPATH)}oniguruma.h
 file.$(OBJEXT): {$(VPATH)}st.h
 file.$(OBJEXT): {$(VPATH)}subst.h
+file.$(OBJEXT): {$(VPATH)}thread.h
 file.$(OBJEXT): {$(VPATH)}util.h
 gc.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
 gc.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
Index: win32/file.c
===================================================================
--- win32/file.c	(revision 50886)
+++ win32/file.c	(revision 50887)
@@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/win32/file.c#L1
 #include "ruby/ruby.h"
 #include "ruby/encoding.h"
+#include "ruby/thread.h"
 #include "internal.h"
 #include <winbase.h>
 #include <wchar.h>
@@ -683,6 +684,14 @@ rb_readlink(VALUE path) https://github.com/ruby/ruby/blob/trunk/win32/file.c#L684
     return append_wstr(rb_enc_str_new(0, 0, enc), wbuf, len, cp, path_cp, enc);
 }
 
+static void *
+loadopen_func(void *wpath)
+{
+    return (void *)CreateFileW(wpath, GENERIC_READ,
+			       FILE_SHARE_READ | FILE_SHARE_WRITE,
+			       NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+}
+
 int
 rb_file_load_ok(const char *path)
 {
@@ -700,9 +709,8 @@ rb_file_load_ok(const char *path) https://github.com/ruby/ruby/blob/trunk/win32/file.c#L709
 	ret = 0;
     }
     else {
-	HANDLE h = CreateFileW(wpath, GENERIC_READ,
-			       FILE_SHARE_READ | FILE_SHARE_WRITE,
-			       NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+	HANDLE h = (HANDLE)rb_thread_call_without_gvl(loadopen_func, (void *)wpath,
+						      RUBY_UBF_IO, 0);
 	if (h != INVALID_HANDLE_VALUE) {
 	    CloseHandle(h);
 	}
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 50886)
+++ test/ruby/test_require.rb	(revision 50887)
@@ -693,4 +693,17 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L693
       INPUT
     }
   end
+
+  def test_loading_fifo_threading
+    Tempfile.create(%w'fifo .rb') {|f|
+      f.close
+      File.unlink(f.path)
+      File.mkfifo(f.path)
+      assert_separately(["-", f.path], <<-END, timeout: 3)
+      th = Thread.current
+      Thread.start {0.1; th.raise(IOError)}
+      assert_raise(IOError) {load(ARGV[0])}
+      END
+    }
+  end
 end
Index: file.c
===================================================================
--- file.c	(revision 50886)
+++ file.c	(revision 50887)
@@ -26,6 +26,7 @@ https://github.com/ruby/ruby/blob/trunk/file.c#L26
 #include "internal.h"
 #include "ruby/io.h"
 #include "ruby/util.h"
+#include "ruby/thread.h"
 #include "dln.h"
 
 #ifdef HAVE_UNISTD_H
@@ -5621,11 +5622,19 @@ rb_path_check(const char *path) https://github.com/ruby/ruby/blob/trunk/file.c#L5622
 }
 
 #ifndef _WIN32
+static void *
+loadopen_func(void *arg)
+{
+    return (void *)(VALUE)rb_cloexec_open((const char *)arg, O_RDONLY, 0);
+}
+
 int
 rb_file_load_ok(const char *path)
 {
     int ret = 1;
-    int fd = rb_cloexec_open(path, O_RDONLY, 0);
+    int fd;
+
+    fd = (int)(VALUE)rb_thread_call_without_gvl(loadopen_func, (void *)path, RUBY_UBF_IO, 0);
     if (fd == -1) return 0;
     rb_update_max_fd(fd);
 #if !defined DOSISH

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

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