mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (nogvl_close, maygvl_close, nogvl_fclose, maygvl_fclose):
new functions. * io.c (fptr_finalize): release GVL if possible. Patched by Eric Wong. [Feature #4570] [ruby-core:35711] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3df2fc2da8
commit
4b58f39ded
2 changed files with 67 additions and 17 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Sun Sep 9 16:47:12 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* io.c (nogvl_close, maygvl_close, nogvl_fclose, maygvl_fclose):
|
||||||
|
new functions.
|
||||||
|
* io.c (fptr_finalize): release GVL if possible.
|
||||||
|
Patched by Eric Wong. [Feature #4570] [ruby-core:35711]
|
||||||
|
|
||||||
Sun Sep 9 16:08:48 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Sun Sep 9 16:08:48 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* io.c (io_bufread): removed unnecessary rb_thread_wait_fd().
|
* io.c (io_bufread): removed unnecessary rb_thread_wait_fd().
|
||||||
|
|
77
io.c
77
io.c
|
@ -3853,10 +3853,51 @@ finish_writeconv_sync(VALUE arg)
|
||||||
return finish_writeconv(p->fptr, p->noalloc);
|
return finish_writeconv(p->fptr, p->noalloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void*
|
||||||
|
nogvl_close(void *ptr)
|
||||||
|
{
|
||||||
|
int *fd = ptr;
|
||||||
|
|
||||||
|
return (void*)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_call_without_gvl(nogvl_close, &fd, RUBY_UBF_IO, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void*
|
||||||
|
nogvl_fclose(void *ptr)
|
||||||
|
{
|
||||||
|
FILE *file = ptr;
|
||||||
|
|
||||||
|
return (void*)fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
maygvl_fclose(FILE *file, int keepgvl)
|
||||||
|
{
|
||||||
|
if (keepgvl)
|
||||||
|
return fclose(file);
|
||||||
|
|
||||||
|
return (int)rb_thread_call_without_gvl(nogvl_fclose, file, RUBY_UBF_IO, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fptr_finalize(rb_io_t *fptr, int noraise)
|
fptr_finalize(rb_io_t *fptr, int noraise)
|
||||||
{
|
{
|
||||||
VALUE err = Qnil;
|
VALUE err = Qnil;
|
||||||
|
int fd = fptr->fd;
|
||||||
|
FILE *stdio_file = fptr->stdio_file;
|
||||||
|
|
||||||
if (fptr->writeconv) {
|
if (fptr->writeconv) {
|
||||||
if (fptr->write_lock && !noraise) {
|
if (fptr->write_lock && !noraise) {
|
||||||
struct finish_writeconv_arg arg;
|
struct finish_writeconv_arg arg;
|
||||||
|
@ -3878,25 +3919,27 @@ fptr_finalize(rb_io_t *fptr, int noraise)
|
||||||
err = INT2NUM(errno);
|
err = INT2NUM(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (IS_PREP_STDIO(fptr) || fptr->fd <= 2) {
|
|
||||||
goto skip_fd_close;
|
|
||||||
}
|
|
||||||
if (fptr->stdio_file) {
|
|
||||||
/* fptr->stdio_file is deallocated anyway
|
|
||||||
* even if fclose failed. */
|
|
||||||
if (fclose(fptr->stdio_file) < 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))
|
|
||||||
err = noraise ? Qtrue : INT2NUM(errno);
|
|
||||||
}
|
|
||||||
skip_fd_close:
|
|
||||||
fptr->fd = -1;
|
fptr->fd = -1;
|
||||||
fptr->stdio_file = 0;
|
fptr->stdio_file = 0;
|
||||||
|
if (!noraise)
|
||||||
|
rb_thread_fd_close(fd);
|
||||||
|
if (IS_PREP_STDIO(fptr) || fd <= 2) {
|
||||||
|
/* need to keep FILE objects of stdin, stdout and stderr */
|
||||||
|
}
|
||||||
|
else if (stdio_file) {
|
||||||
|
/* stdio_file is deallocated anyway
|
||||||
|
* even if fclose failed. */
|
||||||
|
if ((maygvl_fclose(stdio_file, noraise) < 0) && NIL_P(err))
|
||||||
|
err = noraise ? Qtrue : INT2NUM(errno);
|
||||||
|
}
|
||||||
|
else if (0 <= fd) {
|
||||||
|
/* fptr->fd may be closed even if close fails.
|
||||||
|
* POSIX doesn't specify it.
|
||||||
|
* We assumes it is closed. */
|
||||||
|
if ((maygvl_close(fd, noraise) < 0) && NIL_P(err))
|
||||||
|
err = noraise ? Qtrue : INT2NUM(errno);
|
||||||
|
}
|
||||||
fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
|
fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
|
||||||
|
|
||||||
if (!NIL_P(err) && !noraise) {
|
if (!NIL_P(err) && !noraise) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue