summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/io.c b/io.c
index f529658bdb..9103664412 100644
--- a/io.c
+++ b/io.c
@@ -1006,7 +1006,10 @@ 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_async2, (VALUE)fptr);
+ if (rb_mutex_owned_p(fptr->write_lock))
+ return (int)io_flush_buffer_async2((VALUE)fptr);
+ else
+ return (int)rb_mutex_synchronize(fptr->write_lock, io_flush_buffer_async2, (VALUE)fptr);
}
else {
return (int)io_flush_buffer_async((VALUE)fptr);