mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00
* io.c (io_reopen): IO#close releases GVL if possible.
close() may block for certain file types (NFS, SO_LINGER sockets, inotify), so let other threads run. The patch was created by Eric Wong [ruby-core:35555][Bug #4527] * io.c (fptr_finalize): ditto. * io.c (maygvl_fclose): new. * io.c (nogvl_fclose): ditto. * io.c (maygvl_close): ditto. * io.c (nogvl_close): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8a6e9ec085
commit
f35a7770cd
2 changed files with 57 additions and 4 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Sun Apr 3 21:16:20 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* io.c (io_reopen): IO#close releases GVL if possible.
|
||||
close() may block for certain file types (NFS, SO_LINGER
|
||||
sockets, inotify), so let other threads run. The patch was
|
||||
created by Eric Wong [ruby-core:35555][Bug #4527]
|
||||
|
||||
* io.c (fptr_finalize): ditto.
|
||||
|
||||
* io.c (maygvl_fclose): new.
|
||||
* io.c (nogvl_fclose): ditto.
|
||||
* io.c (maygvl_close): ditto.
|
||||
* io.c (nogvl_close): ditto.
|
||||
|
||||
Fri Apr 1 22:25:50 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/syslog/syslog.c: parenthesize macro arguments.
|
||||
|
|
45
io.c
45
io.c
|
@ -3489,6 +3489,45 @@ finish_writeconv_sync(VALUE arg)
|
|||
return finish_writeconv(p->fptr, p->noalloc);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
nogvl_close(void *ptr)
|
||||
{
|
||||
int *fd = ptr;
|
||||
|
||||
return (VALUE)close(*fd);
|
||||
}
|
||||
|
||||
static int
|
||||
maygvl_close(int fd, int keepgvl)
|
||||
{
|
||||
if (keepgvl)
|
||||
return close(fd);
|
||||
|
||||
/*
|
||||
* close() may block for certain file types (NFS, SO_LINGER sockets,
|
||||
* inotify), so let other threads run.
|
||||
*/
|
||||
return (int)rb_thread_blocking_region(nogvl_close, &fd, RUBY_UBF_IO, 0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
nogvl_fclose(void *ptr)
|
||||
{
|
||||
FILE *file = ptr;
|
||||
|
||||
return (VALUE)fclose(file);
|
||||
}
|
||||
|
||||
static int
|
||||
maygvl_fclose(FILE *file, int keepgvl)
|
||||
{
|
||||
if (keepgvl)
|
||||
return fclose(file);
|
||||
|
||||
return (int)rb_thread_blocking_region(nogvl_fclose, file, RUBY_UBF_IO, 0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fptr_finalize(rb_io_t *fptr, int noraise)
|
||||
{
|
||||
|
@ -3520,14 +3559,14 @@ fptr_finalize(rb_io_t *fptr, int noraise)
|
|||
if (fptr->stdio_file) {
|
||||
/* fptr->stdio_file is deallocated anyway
|
||||
* even if fclose failed. */
|
||||
if (fclose(fptr->stdio_file) < 0 && NIL_P(err))
|
||||
if ((maygvl_fclose(fptr->stdio_file, noraise) < 0) && NIL_P(err))
|
||||
err = noraise ? Qtrue : INT2NUM(errno);
|
||||
}
|
||||
else if (0 <= fptr->fd) {
|
||||
/* fptr->fd may be closed even if close fails.
|
||||
* POSIX doesn't specify it.
|
||||
* We assumes it is closed. */
|
||||
if (close(fptr->fd) < 0 && NIL_P(err))
|
||||
if ((maygvl_close(fptr->fd, noraise) < 0) && NIL_P(err))
|
||||
err = noraise ? Qtrue : INT2NUM(errno);
|
||||
}
|
||||
skip_fd_close:
|
||||
|
@ -5784,7 +5823,7 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
rb_sys_fail_path(orig->pathv);
|
||||
}
|
||||
else {
|
||||
fclose(fptr->stdio_file);
|
||||
maygvl_fclose(fptr->stdio_file, 0);
|
||||
fptr->stdio_file = 0;
|
||||
fptr->fd = -1;
|
||||
if (dup2(fd2, fd) < 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue