diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-05-27 09:08:52 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-05-27 09:10:41 +0000 |
commit | 2b5ed135add5562e288017ecafc5f41553d22180 (patch) | |
tree | 9a1b6045423168e0fe9d83ad241c180a43acd3dc /ext | |
parent | 419231017fe2789057aeef5cf9c8eec9ad24bc29 (diff) | |
download | ruby_io_splice-2b5ed135add5562e288017ecafc5f41553d22180.tar.gz |
We can't reliably/efficiently know if the non-pipe descriptor may block, and releasing the GVL is fairly cheap under Linux.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/io_splice/io_splice_ext.c | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c index fdb3397..3a1cf7a 100644 --- a/ext/io_splice/io_splice_ext.c +++ b/ext/io_splice/io_splice_ext.c @@ -10,10 +10,7 @@ #include <limits.h> #include <alloca.h> -#ifdef HAVE_RB_THREAD_BLOCKING_REGION -# define RUBY_1_8_TRAP_BEG for(;0;) -# define RUBY_1_8_TRAP_END for(;0;) -#else +#ifndef HAVE_RB_THREAD_BLOCKING_REGION /* partial emulation of the 1.9 rb_thread_blocking_region under 1.8 */ # include <rubysig.h> # define RUBY_UBF_IO ((rb_unblock_function_t *)-1) @@ -34,8 +31,6 @@ rb_thread_blocking_region( return rv; } -# define RUBY_1_8_TRAP_BEG TRAP_BEG -# define RUBY_1_8_TRAP_END TRAP_END #endif /* ! HAVE_RB_THREAD_BLOCKING_REGION */ #ifndef RSTRING_PTR @@ -77,21 +72,9 @@ struct splice_args { static VALUE nogvl_splice(void *ptr) { struct splice_args *a = ptr; - long n; - - /* - * it's still possible to block because the SPLICE_F_NONBLOCK flag - * only affects the pipe descriptor, not the non-pipe descriptor. - * So use TRAP_BEG/TRAP_END (only) to make Ruby 1.8 happy. We also - * don't want the TRAP_BEG/TRAP_END compatibility layer in 1.9, - * so we use the 1.8-only versions - */ - RUBY_1_8_TRAP_BEG; - n = splice(a->fd_in, a->off_in, a->fd_out, a->off_out, - a->len, a->flags); - RUBY_1_8_TRAP_END; - return (VALUE)n; + return (VALUE)splice(a->fd_in, a->off_in, a->fd_out, a->off_out, + a->len, a->flags); } /* @@ -146,7 +129,7 @@ static VALUE my_splice(VALUE self, .flags = NUM2UINT(flags), }; - n = (long)nb_io_run(nogvl_splice, &a, a.flags); + n = (long)rb_thread_blocking_region(nogvl_splice, &a, RUBY_UBF_IO, 0); if (n == 0) rb_eof_error(); if (n < 0) |