From abf832f4357b02ab40a1bbcb6e59bbc1c35d2817 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 16 Oct 2015 06:54:38 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index f2b760aa0c..5a5fcde229 100644 --- a/file.c +++ b/file.c @@ -26,7 +26,6 @@ #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) } #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; } } -- cgit v1.2.3