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

ruby-changes:40058

From: nobu <ko1@a...>
Date: Fri, 16 Oct 2015 15:54:51 +0900 (JST)
Subject: [ruby-changes:40058] nobu:r52139 (trunk): file.c: non-blocking open

nobu	2015-10-16 15:54:38 +0900 (Fri, 16 Oct 2015)

  New Revision: 52139

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

  Log:
    file.c: non-blocking open
    
    * file.c (rb_file_load_ok): open in non-blocking mode withoout
      releasing GVL.  don't care about others than regular files and
      directories.  [ruby-dev:49272] [Bug #11559]
    * ruby.c (load_file_internal): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/file.c
    trunk/ruby.c
    trunk/test/ruby/test_require.rb
    trunk/win32/file.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52138)
+++ ChangeLog	(revision 52139)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 16 15:54:37 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_file_load_ok): open in non-blocking mode withoout
+	  releasing GVL.  don't care about others than regular files and
+	  directories.  [ruby-dev:49272] [Bug #11559]
+
+	* ruby.c (load_file_internal): ditto.
+
 Thu Oct 15 23:56:03 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* proc.c (rb_sym_to_proc): make void env.
Index: common.mk
===================================================================
--- common.mk	(revision 52138)
+++ common.mk	(revision 52139)
@@ -728,7 +728,7 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc https://github.com/ruby/ruby/blob/trunk/common.mk#L728
 win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \
   {$(VPATH)}dln.h {$(VPATH)}dln_find.c {$(VPATH)}encindex.h \
   {$(VPATH)}internal.h {$(VPATH)}util.h $(RUBY_H_INCLUDES) $(PLATFORM_D)
-win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}win32/file.h {$(VPATH)}thread.h \
+win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}win32/file.h \
   $(RUBY_H_INCLUDES) $(PLATFORM_D)
 
 $(NEWLINE_C): $(srcdir)/enc/trans/newline.trans $(srcdir)/tool/transcode-tblgen.rb
@@ -1462,7 +1462,6 @@ file.$(OBJEXT): {$(VPATH)}missing.h https://github.com/ruby/ruby/blob/trunk/common.mk#L1462
 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 52138)
+++ win32/file.c	(revision 52139)
@@ -4,7 +4,6 @@ https://github.com/ruby/ruby/blob/trunk/win32/file.c#L4
 #endif
 #include "ruby/ruby.h"
 #include "ruby/encoding.h"
-#include "ruby/thread.h"
 #include "internal.h"
 #include <winbase.h>
 #include <wchar.h>
@@ -700,14 +699,6 @@ rb_readlink(VALUE path, rb_encoding *res https://github.com/ruby/ruby/blob/trunk/win32/file.c#L699
     return str;
 }
 
-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)
 {
@@ -725,8 +716,9 @@ rb_file_load_ok(const char *path) https://github.com/ruby/ruby/blob/trunk/win32/file.c#L716
 	ret = 0;
     }
     else {
-	HANDLE h = (HANDLE)rb_thread_call_without_gvl(loadopen_func, (void *)wpath,
-						      RUBY_UBF_IO, 0);
+	HANDLE h = CreateFileW(wpath, GENERIC_READ,
+			       FILE_SHARE_READ | FILE_SHARE_WRITE,
+			       NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 	if (h != INVALID_HANDLE_VALUE) {
 	    CloseHandle(h);
 	}
Index: ruby.c
===================================================================
--- ruby.c	(revision 52138)
+++ ruby.c	(revision 52139)
@@ -1739,6 +1739,11 @@ load_file_internal(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1739
     }
     else {
 	int fd, mode = O_RDONLY;
+#if defined O_NONBLOCK
+	mode |= O_NONBLOCK;
+#elif defined O_NDELAY
+	mod |= O_NDELAY;
+#endif
 #if defined DOSISH || defined __CYGWIN__
 	{
 	    const char *ext = strrchr(fname, '.');
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 52138)
+++ test/ruby/test_require.rb	(revision 52139)
@@ -702,7 +702,12 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L702
       assert_separately(["-", f.path], <<-END, timeout: 3)
       th = Thread.current
       Thread.start {begin sleep(0.001) end until th.stop?; th.raise(IOError)}
-      assert_raise(IOError) {load(ARGV[0])}
+      assert_nothing_raised do
+        begin
+          load(ARGV[0])
+        rescue IOError
+        end
+      end
       END
     }
   end unless /mswin|mingw/ =~ RUBY_PLATFORM
Index: file.c
===================================================================
--- file.c	(revision 52138)
+++ file.c	(revision 52139)
@@ -26,7 +26,6 @@ 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"
 #include "encindex.h"
 
@@ -5665,25 +5664,24 @@ rb_path_check(const char *path) https://github.com/ruby/ruby/blob/trunk/file.c#L5664
 }
 
 #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;
-
-    fd = (int)(VALUE)rb_thread_call_without_gvl(loadopen_func, (void *)path, RUBY_UBF_IO, 0);
+    int mode = (O_RDONLY |
+#if defined O_NONBLOCK
+		O_NONBLOCK |
+#elif defined O_NDELAY
+		O_NDELAY |
+#endif
+		0);
+    int fd = rb_cloexec_open(path, mode, 0);
     if (fd == -1) return 0;
     rb_update_max_fd(fd);
 #if !defined DOSISH
     {
 	struct stat st;
-	if (fstat(fd, &st) || !S_ISREG(st.st_mode)) {
+	if (fstat(fd, &st) || S_ISDIR(st.st_mode)) {
 	    ret = 0;
 	}
     }

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

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