mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
6291c6ad77
commit
abf832f435
6 changed files with 32 additions and 25 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Fri Oct 16 15:54:37 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Thu Oct 15 23:56:03 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* proc.c (rb_sym_to_proc): make void env.
|
* proc.c (rb_sym_to_proc): make void env.
|
||||||
|
|
|
@ -728,7 +728,7 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc {$(VPATH)}optunifs.inc
|
||||||
win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \
|
win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \
|
||||||
{$(VPATH)}dln.h {$(VPATH)}dln_find.c {$(VPATH)}encindex.h \
|
{$(VPATH)}dln.h {$(VPATH)}dln_find.c {$(VPATH)}encindex.h \
|
||||||
{$(VPATH)}internal.h {$(VPATH)}util.h $(RUBY_H_INCLUDES) $(PLATFORM_D)
|
{$(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)
|
$(RUBY_H_INCLUDES) $(PLATFORM_D)
|
||||||
|
|
||||||
$(NEWLINE_C): $(srcdir)/enc/trans/newline.trans $(srcdir)/tool/transcode-tblgen.rb
|
$(NEWLINE_C): $(srcdir)/enc/trans/newline.trans $(srcdir)/tool/transcode-tblgen.rb
|
||||||
|
@ -1462,7 +1462,6 @@ file.$(OBJEXT): {$(VPATH)}missing.h
|
||||||
file.$(OBJEXT): {$(VPATH)}oniguruma.h
|
file.$(OBJEXT): {$(VPATH)}oniguruma.h
|
||||||
file.$(OBJEXT): {$(VPATH)}st.h
|
file.$(OBJEXT): {$(VPATH)}st.h
|
||||||
file.$(OBJEXT): {$(VPATH)}subst.h
|
file.$(OBJEXT): {$(VPATH)}subst.h
|
||||||
file.$(OBJEXT): {$(VPATH)}thread.h
|
|
||||||
file.$(OBJEXT): {$(VPATH)}util.h
|
file.$(OBJEXT): {$(VPATH)}util.h
|
||||||
gc.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
|
gc.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
|
||||||
gc.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
|
gc.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
|
||||||
|
|
20
file.c
20
file.c
|
@ -26,7 +26,6 @@
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "ruby/io.h"
|
#include "ruby/io.h"
|
||||||
#include "ruby/util.h"
|
#include "ruby/util.h"
|
||||||
#include "ruby/thread.h"
|
|
||||||
#include "dln.h"
|
#include "dln.h"
|
||||||
#include "encindex.h"
|
#include "encindex.h"
|
||||||
|
|
||||||
|
@ -5665,25 +5664,24 @@ rb_path_check(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static void *
|
|
||||||
loadopen_func(void *arg)
|
|
||||||
{
|
|
||||||
return (void *)(VALUE)rb_cloexec_open((const char *)arg, O_RDONLY, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_file_load_ok(const char *path)
|
rb_file_load_ok(const char *path)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
int fd;
|
int mode = (O_RDONLY |
|
||||||
|
#if defined O_NONBLOCK
|
||||||
fd = (int)(VALUE)rb_thread_call_without_gvl(loadopen_func, (void *)path, RUBY_UBF_IO, 0);
|
O_NONBLOCK |
|
||||||
|
#elif defined O_NDELAY
|
||||||
|
O_NDELAY |
|
||||||
|
#endif
|
||||||
|
0);
|
||||||
|
int fd = rb_cloexec_open(path, mode, 0);
|
||||||
if (fd == -1) return 0;
|
if (fd == -1) return 0;
|
||||||
rb_update_max_fd(fd);
|
rb_update_max_fd(fd);
|
||||||
#if !defined DOSISH
|
#if !defined DOSISH
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (fstat(fd, &st) || !S_ISREG(st.st_mode)) {
|
if (fstat(fd, &st) || S_ISDIR(st.st_mode)) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
ruby.c
5
ruby.c
|
@ -1739,6 +1739,11 @@ load_file_internal(VALUE arg)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int fd, mode = O_RDONLY;
|
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__
|
#if defined DOSISH || defined __CYGWIN__
|
||||||
{
|
{
|
||||||
const char *ext = strrchr(fname, '.');
|
const char *ext = strrchr(fname, '.');
|
||||||
|
|
|
@ -702,7 +702,12 @@ class TestRequire < Test::Unit::TestCase
|
||||||
assert_separately(["-", f.path], <<-END, timeout: 3)
|
assert_separately(["-", f.path], <<-END, timeout: 3)
|
||||||
th = Thread.current
|
th = Thread.current
|
||||||
Thread.start {begin sleep(0.001) end until th.stop?; th.raise(IOError)}
|
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
|
||||||
}
|
}
|
||||||
end unless /mswin|mingw/ =~ RUBY_PLATFORM
|
end unless /mswin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
|
14
win32/file.c
14
win32/file.c
|
@ -4,7 +4,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
#include "ruby/thread.h"
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
@ -700,14 +699,6 @@ rb_readlink(VALUE path, rb_encoding *resultenc)
|
||||||
return str;
|
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
|
int
|
||||||
rb_file_load_ok(const char *path)
|
rb_file_load_ok(const char *path)
|
||||||
{
|
{
|
||||||
|
@ -725,8 +716,9 @@ rb_file_load_ok(const char *path)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
HANDLE h = (HANDLE)rb_thread_call_without_gvl(loadopen_func, (void *)wpath,
|
HANDLE h = CreateFileW(wpath, GENERIC_READ,
|
||||||
RUBY_UBF_IO, 0);
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
if (h != INVALID_HANDLE_VALUE) {
|
if (h != INVALID_HANDLE_VALUE) {
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue