aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-25 14:34:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-25 14:34:07 +0000
commit54b36c6df609b0478c11589a0d5eb5dda902da7d (patch)
tree89c4fa4d83f1e8308c02485ea8623b823b697343 /io.c
parentd7f0e13912b71cb957b7923bd53641c87a9e75f6 (diff)
downloadruby-54b36c6df609b0478c11589a0d5eb5dda902da7d.tar.gz
io.c: close before wait
* io.c (io_close_fptr): notify then close, and wait for other threads before free fptr. [ruby-core:79262] [Bug #13158] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/io.c b/io.c
index 4bcddf4cf9..322aabedc5 100644
--- a/io.c
+++ b/io.c
@@ -4271,7 +4271,7 @@ static void free_io_buffer(rb_io_buffer_t *buf);
static void clear_codeconv(rb_io_t *fptr);
static void
-fptr_finalize(rb_io_t *fptr, int noraise)
+fptr_finalize_flush(rb_io_t *fptr, int noraise)
{
VALUE err = Qnil;
int fd = fptr->fd;
@@ -4331,6 +4331,12 @@ fptr_finalize(rb_io_t *fptr, int noraise)
else
rb_exc_raise(err);
}
+}
+
+static void
+fptr_finalize(rb_io_t *fptr, int noraise)
+{
+ fptr_finalize_flush(fptr, noraise);
free_io_buffer(&fptr->rbuf);
free_io_buffer(&fptr->wbuf);
clear_codeconv(fptr);
@@ -4410,6 +4416,7 @@ rb_io_memsize(const rb_io_t *fptr)
return size;
}
+int rb_notify_fd_close(int fd);
static rb_io_t *
io_close_fptr(VALUE io)
{
@@ -4417,6 +4424,7 @@ io_close_fptr(VALUE io)
int fd;
VALUE write_io;
rb_io_t *write_fptr;
+ int busy;
write_io = GetWriteIO(io);
if (io != write_io) {
@@ -4431,7 +4439,11 @@ io_close_fptr(VALUE io)
if (fptr->fd < 0) return 0;
fd = fptr->fd;
- rb_thread_fd_close(fd);
+ busy = rb_notify_fd_close(fd);
+ fptr_finalize_flush(fptr, FALSE);
+ if (busy) {
+ do rb_thread_schedule(); while (rb_notify_fd_close(fd));
+ }
rb_io_fptr_cleanup(fptr, FALSE);
return fptr;
}
@@ -6762,7 +6774,7 @@ io_reopen(VALUE io, VALUE nfile)
rb_update_max_fd(fd);
fptr->fd = fd;
}
- rb_thread_fd_close(fd);
+ rb_notify_fd_close(fd);
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
if (io_seek(fptr, pos, SEEK_SET) < 0 && errno) {
rb_sys_fail_path(fptr->pathv);