From 9bd33790b7f992520f003954df743dd6e8502622 Mon Sep 17 00:00:00 2001 From: kosaki Date: Sat, 15 Dec 2012 05:40:07 +0000 Subject: * io.c (io_flush_buffer): uses io_flush_buffer_async2 instead of io_flush_buffer_async. * io.c (io_flush_buffer_async2): new helper function for io_flush_buffer. It uses rb_thread_call_without_gvl2() instead of rb_thread_io_blocking_region. * io.c (io_flush_buffer_sync2): new helper function for io_flush_buffer_async2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ io.c | 25 ++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f7a45c9381..a8f220aaa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sat Dec 15 13:38:30 2012 KOSAKI Motohiro + + * io.c (io_flush_buffer): uses io_flush_buffer_async2 instead of + io_flush_buffer_async. + * io.c (io_flush_buffer_async2): new helper function for + io_flush_buffer. It uses rb_thread_call_without_gvl2() instead + of rb_thread_io_blocking_region. + * io.c (io_flush_buffer_sync2): new helper function for + io_flush_buffer_async2. + Sat Dec 15 13:04:26 2012 KOSAKI Motohiro * io.c (internal_write_func2): new helper function for rb_write_internal2(). diff --git a/io.c b/io.c index 8b7a9c9d1c..f529658bdb 100644 --- a/io.c +++ b/io.c @@ -972,6 +972,12 @@ io_flush_buffer_sync(void *arg) return (VALUE)-1; } +static void* +io_flush_buffer_sync2(void *arg) +{ + return (void*)io_flush_buffer_sync(arg); +} + static VALUE io_flush_buffer_async(VALUE arg) { @@ -979,11 +985,28 @@ io_flush_buffer_async(VALUE arg) return rb_thread_io_blocking_region(io_flush_buffer_sync, fptr, fptr->fd); } +static VALUE +io_flush_buffer_async2(VALUE arg) +{ + rb_io_t *fptr = (rb_io_t *)arg; + void *ret; + + ret = rb_thread_call_without_gvl2(io_flush_buffer_sync2, fptr, + RUBY_UBF_IO, NULL); + + /* pending async interrupt is there. */ + if (!ret) { + errno = EAGAIN; + return (VALUE)-1; + } + return (VALUE) ret; +} + static inline int io_flush_buffer(rb_io_t *fptr) { if (fptr->write_lock) { - return (int)rb_mutex_synchronize(fptr->write_lock, io_flush_buffer_async, (VALUE)fptr); + return (int)rb_mutex_synchronize(fptr->write_lock, io_flush_buffer_async2, (VALUE)fptr); } else { return (int)io_flush_buffer_async((VALUE)fptr); -- cgit v1.2.3