From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS12876 163.172.0.0/16 X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (tor-exit-readme.memcpy.io [163.172.67.180]) by dcvr.yhbt.net (Postfix) with ESMTP id 46F6B207EC for ; Wed, 26 Apr 2017 01:11:03 +0000 (UTC) From: Eric Wong To: raindrops-public@bogomips.org Subject: [PATCH] Ruby thread compatibility updates Date: Wed, 26 Apr 2017 01:10:59 +0000 Message-Id: <20170426011059.17792-1-e@80x24.org> List-Id: Drop vestigial Ruby 1.8 bits, and start using rb_thread_call_without_gvl on modern Rubies. --- ext/raindrops/extconf.rb | 1 + ext/raindrops/linux_inet_diag.c | 52 ++++++++++++----------------------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/ext/raindrops/extconf.rb b/ext/raindrops/extconf.rb index 86c7d78..7570f24 100644 --- a/ext/raindrops/extconf.rb +++ b/ext/raindrops/extconf.rb @@ -112,6 +112,7 @@ end have_func("getpagesize", "unistd.h") +have_func('rb_thread_call_without_gvl') have_func('rb_thread_blocking_region') have_func('rb_thread_io_blocking_region') diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c index f2db6a5..615c931 100644 --- a/ext/raindrops/linux_inet_diag.c +++ b/ext/raindrops/linux_inet_diag.c @@ -1,46 +1,24 @@ #include #include -#ifdef HAVE_RUBY_ST_H -# include -#else -# include -#endif +#include #include "my_fileno.h" #ifdef __linux__ -/* Ruby 1.8.6+ macros (for compatibility with Ruby 1.9) */ -#ifndef RSTRING_LEN -# define RSTRING_LEN(s) (RSTRING(s)->len) -#endif - -/* partial emulation of the 1.9 rb_thread_blocking_region under 1.8 */ -#if !defined(HAVE_RB_THREAD_BLOCKING_REGION) && \ - !defined(HAVE_RB_THREAD_IO_BLOCKING_REGION) -# include -# define RUBY_UBF_IO ((rb_unblock_function_t *)-1) -typedef void rb_unblock_function_t(void *); -typedef VALUE rb_blocking_function_t(void *); -static VALUE -rb_thread_blocking_region( - rb_blocking_function_t *func, void *data1, - rb_unblock_function_t *ubf, void *data2) -{ - VALUE rv; - - TRAP_BEG; - rv = func(data1); - TRAP_END; - - return rv; -} -#endif /* ! HAVE_RB_THREAD_BLOCKING_REGION */ - #ifdef HAVE_RB_THREAD_IO_BLOCKING_REGION +/* Ruby 1.9.3 and 2.0.0 */ VALUE rb_thread_io_blocking_region(rb_blocking_function_t *, void *, int); +# define rd_fd_region(fn,data,fd) \ + rb_thread_io_blocking_region((fn),(data),(fd)) +#elif defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \ + defined(HAVE_RUBY_THREAD_H) && HAVE_RUBY_THREAD_H +/* in case Ruby 2.0+ ever drops rb_thread_io_blocking_region: */ +# include +# define COMPAT_FN (void *(*)(void *)) +# define rd_fd_region(fn,data,fd) \ + rb_thread_call_without_gvl(COMPAT_FN(fn),(data),RUBY_UBF_IO,NULL) #else -# define rb_thread_io_blocking_region(fn,data,fd) \ - rb_thread_blocking_region((fn),(data),RUBY_UBF_IO,0) -#endif /* HAVE_RB_THREAD_IO_BLOCKING_REGION */ +# error Ruby <= 1.8 not supported +#endif #include #include @@ -608,7 +586,7 @@ static VALUE tcp_stats(struct nogvl_args *args, VALUE addr) gen_bytecode(&args->iov[2], &query_addr); memset(&args->stats, 0, sizeof(struct listen_stats)); - nl_errcheck(rb_thread_io_blocking_region(diag, args, args->fd)); + nl_errcheck(rd_fd_region(diag, args, args->fd)); return rb_listen_stats(&args->stats); } @@ -685,7 +663,7 @@ static VALUE tcp_listener_stats(int argc, VALUE *argv, VALUE self) "addr must be an array of strings, a string, or nil"); } - nl_errcheck(rb_thread_io_blocking_region(diag, &args, args.fd)); + nl_errcheck(rd_fd_region(diag, &args, args.fd)); st_foreach(args.table, NIL_P(addrs) ? st_to_hash : st_AND_hash, rv); st_free_table(args.table); -- EW