From 6299ef55e20454eaca0b9860ac4a9bd6ddd143a7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 14 Mar 2011 19:35:01 +0000 Subject: use rb_thread_blocking_io_region if possible It's in Ruby 1.9.3dev and tracks waiting FDs on blocked threads. --- ext/kgio/accept.c | 3 ++- ext/kgio/blocking_io_region.h | 6 ++++++ ext/kgio/extconf.rb | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 ext/kgio/blocking_io_region.h diff --git a/ext/kgio/accept.c b/ext/kgio/accept.c index 902145c..2026a78 100644 --- a/ext/kgio/accept.c +++ b/ext/kgio/accept.c @@ -69,6 +69,7 @@ static VALUE xaccept(void *ptr) #ifdef HAVE_RB_THREAD_BLOCKING_REGION # include +# include "blocking_io_region.h" /* * Try to use a (real) blocking accept() since that can prevent * thundering herds under Linux: @@ -82,7 +83,7 @@ static int thread_accept(struct accept_args *a, int force_nonblock) { if (force_nonblock) set_nonblocking(a->fd); - return (int)rb_thread_blocking_region(xaccept, a, RUBY_UBF_IO, 0); + return (int)rb_thread_io_blocking_region(xaccept, a, a->fd); } static void set_blocking_or_block(int fd) diff --git a/ext/kgio/blocking_io_region.h b/ext/kgio/blocking_io_region.h new file mode 100644 index 0000000..c872b53 --- /dev/null +++ b/ext/kgio/blocking_io_region.h @@ -0,0 +1,6 @@ +#ifdef HAVE_RB_THREAD_BLOCKING_REGION +# ifndef HAVE_RB_THREAD_IO_BLOCKING_REGION +# define rb_thread_io_blocking_region(fn,data,fd) \ + rb_thread_blocking_region((fn),(data),RUBY_UBF_IO,0) +# endif +#endif diff --git a/ext/kgio/extconf.rb b/ext/kgio/extconf.rb index d7f1299..a0def1d 100644 --- a/ext/kgio/extconf.rb +++ b/ext/kgio/extconf.rb @@ -27,6 +27,7 @@ have_type("struct RObject") and check_sizeof("struct RObject") check_sizeof("int") have_func('rb_io_ascii8bit_binmode') have_func('rb_thread_blocking_region') +have_func('rb_thread_io_blocking_region') have_func('rb_str_set_len') dir_config('kgio') -- cgit v1.2.3-24-ge0c7