mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
file.c: open without gvl
* file.c (rb_file_load_ok): try opening file without gvl not to lock entire process. [Bug #11060] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9b04c1dd42
commit
0b3ef899f2
5 changed files with 42 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Jun 14 17:20:40 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* tool/runruby.rb: just remove the lines of RUBY_VERSION check and raise
|
||||
|
|
|
@ -713,7 +713,8 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc {$(VPATH)}optunifs.inc
|
|||
|
||||
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
|
|||
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
|
||||
|
|
11
file.c
11
file.c
|
@ -26,6 +26,7 @@
|
|||
#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)
|
|||
}
|
||||
|
||||
#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
|
||||
|
|
|
@ -693,4 +693,17 @@ class TestRequire < Test::Unit::TestCase
|
|||
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
|
||||
|
|
14
win32/file.c
14
win32/file.c
|
@ -1,5 +1,6 @@
|
|||
#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)
|
|||
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)
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue