From 008483785d1a5bb801219af8afbb77be18b9bef1 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Mon, 20 Jan 2014 22:36:19 +0300 Subject: Don't use deprecated api Signed-off-by: Eric Wong --- ext/kgio/accept.c | 8 ++++---- ext/kgio/blocking_io_region.h | 9 ++++++--- ext/kgio/connect.c | 4 ++-- ext/kgio/extconf.rb | 2 ++ ext/kgio/kgio.h | 14 +++++++++++++- ext/kgio/tryopen.c | 5 +++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/ext/kgio/accept.c b/ext/kgio/accept.c index 67a8ded..911e169 100644 --- a/ext/kgio/accept.c +++ b/ext/kgio/accept.c @@ -10,7 +10,7 @@ static VALUE cKgio_Socket; static VALUE mSocketMethods; static VALUE iv_kgio_addr; -#if defined(__linux__) && defined(HAVE_RB_THREAD_BLOCKING_REGION) +#if defined(__linux__) && defined(KGIO_HAVE_THREAD_CALL_WITHOUT_GVL) static int accept4_flags = SOCK_CLOEXEC; #else /* ! linux */ static int accept4_flags = SOCK_CLOEXEC | SOCK_NONBLOCK; @@ -76,7 +76,7 @@ static VALUE xaccept(void *ptr) return (VALUE)rv; } -#ifdef HAVE_RB_THREAD_BLOCKING_REGION +#ifdef KGIO_HAVE_THREAD_CALL_WITHOUT_GVL # include # include "blocking_io_region.h" static int thread_accept(struct accept_args *a, int force_nonblock) @@ -86,7 +86,7 @@ static int thread_accept(struct accept_args *a, int force_nonblock) return (int)rb_thread_io_blocking_region(xaccept, a, a->fd); } -#else /* ! HAVE_RB_THREAD_BLOCKING_REGION */ +#else /* ! KGIO_HAVE_THREAD_CALL_WITHOUT_GVL */ # include static int thread_accept(struct accept_args *a, int force_nonblock) { @@ -103,7 +103,7 @@ static int thread_accept(struct accept_args *a, int force_nonblock) TRAP_END; return rv; } -#endif /* ! HAVE_RB_THREAD_BLOCKING_REGION */ +#endif /* ! KGIO_HAVE_THREAD_CALL_WITHOUT_GVL */ static void prepare_accept(struct accept_args *a, VALUE self, int argc, const VALUE *argv) diff --git a/ext/kgio/blocking_io_region.h b/ext/kgio/blocking_io_region.h index 30c7106..10e7533 100644 --- a/ext/kgio/blocking_io_region.h +++ b/ext/kgio/blocking_io_region.h @@ -1,8 +1,11 @@ -#ifdef HAVE_RB_THREAD_BLOCKING_REGION -# ifdef HAVE_RB_THREAD_IO_BLOCKING_REGION +#ifdef KGIO_HAVE_THREAD_CALL_WITHOUT_GVL +# if defined(HAVE_RB_THREAD_IO_BLOCKING_REGION) /* temporary API for Ruby 1.9.3 */ VALUE rb_thread_io_blocking_region(rb_blocking_function_t *, void *, int); -# else +# elif defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) +# define rb_thread_io_blocking_region(fn,data,fd) \ + rb_thread_call_without_gvl((fn),(data),RUBY_UBF_IO,0) +# elif defined(HAVE_RB_THREAD_BLOCKING_REGION) # define rb_thread_io_blocking_region(fn,data,fd) \ rb_thread_blocking_region((fn),(data),RUBY_UBF_IO,0) # endif diff --git a/ext/kgio/connect.c b/ext/kgio/connect.c index 2027795..ef1a396 100644 --- a/ext/kgio/connect.c +++ b/ext/kgio/connect.c @@ -143,7 +143,7 @@ static struct sockaddr *sockaddr_from(socklen_t *addrlen, VALUE addr) return NULL; } -#if defined(MSG_FASTOPEN) && defined(HAVE_RB_THREAD_BLOCKING_REGION) +#if defined(MSG_FASTOPEN) && defined(KGIO_HAVE_THREAD_CALL_WITHOUT_GVL) #ifndef HAVE_RB_STR_SUBSEQ #define rb_str_subseq rb_str_substr #endif @@ -381,7 +381,7 @@ void init_kgio_connect(void) rb_define_singleton_method(cKgio_Socket, "new", kgio_new, -1); rb_define_singleton_method(cKgio_Socket, "connect", kgio_connect, 1); rb_define_singleton_method(cKgio_Socket, "start", kgio_start, 1); -#if defined(MSG_FASTOPEN) && defined(HAVE_RB_THREAD_BLOCKING_REGION) +#if defined(MSG_FASTOPEN) && defined(KGIO_HAVE_THREAD_CALL_WITHOUT_GVL) rb_define_method(cKgio_Socket, "kgio_fastopen", fastopen, 2); #endif /* diff --git a/ext/kgio/extconf.rb b/ext/kgio/extconf.rb index 5fb15ac..44888dd 100644 --- a/ext/kgio/extconf.rb +++ b/ext/kgio/extconf.rb @@ -46,6 +46,8 @@ have_func('rb_io_ascii8bit_binmode') have_func('rb_update_max_fd') have_func('rb_fd_fix_cloexec') have_func('rb_cloexec_open') +have_header('ruby/thread.h') +have_func('rb_thread_call_without_gvl', %w{ruby/thread.h}) have_func('rb_thread_blocking_region') have_func('rb_thread_io_blocking_region') have_func('rb_str_set_len') diff --git a/ext/kgio/kgio.h b/ext/kgio/kgio.h index 983280d..0c689a3 100644 --- a/ext/kgio/kgio.h +++ b/ext/kgio/kgio.h @@ -7,6 +7,9 @@ #else # include #endif +#ifdef HAVE_RUBY_THREAD_H +# include +#endif #include #include #include @@ -42,7 +45,16 @@ void kgio_autopush_send(VALUE); VALUE kgio_call_wait_writable(VALUE io); VALUE kgio_call_wait_readable(VALUE io); -#if defined(HAVE_RB_THREAD_BLOCKING_REGION) && defined(HAVE_POLL) +#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) +# define KGIO_HAVE_THREAD_CALL_WITHOUT_GVL 1 +typedef void *(*kgio_blocking_fn_t)(void*); +# define rb_thread_blocking_region(fn,data1,ubf,data2) \ + rb_thread_call_without_gvl((kgio_blocking_fn_t)(fn),(data1),(ubf),(data2)) +#elif defined(HAVE_RB_THREAD_BLOCKING_REGION) +# define KGIO_HAVE_THREAD_CALL_WITHOUT_GVL 1 +#endif /* HAVE_RB_THREAD_CALL_WITHOUT_GVL || HAVE_RB_THREAD_BLOCKING_REGION */ + +#if defined(KGIO_HAVE_THREAD_CALL_WITHOUT_GVL) && defined(HAVE_POLL) # define USE_KGIO_POLL #endif /* USE_KGIO_POLL */ diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c index 902c745..1d8fffd 100644 --- a/ext/kgio/tryopen.c +++ b/ext/kgio/tryopen.c @@ -17,6 +17,7 @@ #include #include "set_file_path.h" #include "ancient_ruby.h" +#include "kgio.h" static ID id_for_fd, id_to_path, id_path; static st_table *errno2sym; @@ -38,7 +39,7 @@ static VALUE nogvl_open(void *ptr) return (VALUE)rb_cloexec_open(o->pathname, o->flags, o->mode); } -#ifndef HAVE_RB_THREAD_BLOCKING_REGION +#ifndef KGIO_HAVE_THREAD_CALL_WITHOUT_GVL # define RUBY_UBF_IO ((void *)(-1)) # include "rubysig.h" typedef void rb_unblock_function_t(void *); @@ -57,7 +58,7 @@ static VALUE my_thread_blocking_region( } #define rb_thread_blocking_region(fn,data1,ubf,data2) \ my_thread_blocking_region((fn),(data1),(ubf),(data2)) -#endif /* ! HAVE_RB_THREAD_BLOCKING_REGION */ +#endif /* ! KGIO_HAVE_THREAD_CALL_WITHOUT_GVL */ /* * call-seq: -- cgit v1.2.3-24-ge0c7