From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.clogger.general Subject: [PATCH 6/6] use rb_thread_call_without_gvl for Ruby 2+ Date: Sat, 15 Feb 2014 23:09:08 +0000 Message-ID: <1392505748-13740-6-git-send-email-normalperson@yhbt.net> References: <1392505748-13740-1-git-send-email-normalperson@yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1392505764 7039 80.91.229.3 (15 Feb 2014 23:09:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 15 Feb 2014 23:09:24 +0000 (UTC) To: clogger@librelist.org Original-X-From: clogger@librelist.org Sun Feb 16 00:09:30 2014 Return-path: Envelope-to: gcrcg-clogger@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: clogger@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.clogger.general:66 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WEoMU-0000ze-Hb for gcrcg-clogger@m.gmane.org; Sun, 16 Feb 2014 00:09:30 +0100 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id DA8A575019 for ; Sat, 15 Feb 2014 23:18:33 +0000 (UTC) rb_thread_blocking_region is deprecated and will be removed --- ext/clogger_ext/blocking_helpers.h | 34 ++++++++++++++++++++++++++-------- ext/clogger_ext/extconf.rb | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ext/clogger_ext/blocking_helpers.h b/ext/clogger_ext/blocking_helpers.h index bb366ff..c03c2f5 100644 --- a/ext/clogger_ext/blocking_helpers.h +++ b/ext/clogger_ext/blocking_helpers.h @@ -1,27 +1,45 @@ -#ifdef HAVE_RB_THREAD_BLOCKING_REGION -struct stat_args { const char *path; struct stat *buf; }; -static VALUE ng_stat(void *ptr) +#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && defined(HAVE_RUBY_THREAD_H) +/* Ruby 2.0+ */ +# include +# define WITHOUT_GVL(fn,a,ubf,b) \ + rb_thread_call_without_gvl((fn),(a),(ubf),(b)) +#elif defined(HAVE_RB_THREAD_BLOCKING_REGION) +typedef VALUE (*my_blocking_fn_t)(void*); +# define WITHOUT_GVL(fn,a,ubf,b) \ + rb_thread_blocking_region((my_blocking_fn_t)(fn),(a),(ubf),(b)) +#endif + +#ifdef WITHOUT_GVL +struct stat_args { int err; const char *path; struct stat *buf; }; +static void * ng_stat(void *ptr) { struct stat_args *a = ptr; - return (VALUE)stat(a->path, a->buf); + a->err = stat(a->path, a->buf); + return NULL; } + static int my_stat(const char *path, struct stat *buf) { struct stat_args a; a.path = path; a.buf = buf; - return (int)rb_thread_blocking_region(ng_stat, &a, RUBY_UBF_IO, 0); + WITHOUT_GVL(ng_stat, &a, RUBY_UBF_IO, 0); + return a.err; } + #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) + WITHOUT_GVL((fn),(data), RUBY_UBF_IO, 0) +#else + VALUE rb_thread_io_blocking_region(VALUE(*)(void *), void *, int); #endif struct write_args { int fd; const void *buf; size_t count; }; static VALUE ng_write(void *ptr) { struct write_args *a = ptr; + return (VALUE)write(a->fd, a->buf, a->count); } static ssize_t my_write(int fd, const void *buf, size_t count) @@ -36,6 +54,6 @@ static ssize_t my_write(int fd, const void *buf, size_t count) return r; } -# define stat(fd,buf) my_stat((fd),(buf)) +# define stat(path,buf) my_stat((path),(buf)) # define write(fd,buf,count) my_write((fd),(buf),(count)) -#endif +#endif /* !WITHOUT_GVL */ diff --git a/ext/clogger_ext/extconf.rb b/ext/clogger_ext/extconf.rb index 99f7deb..523b314 100644 --- a/ext/clogger_ext/extconf.rb +++ b/ext/clogger_ext/extconf.rb @@ -19,6 +19,7 @@ begin have_func('gmtime_r', 'time.h') or raise "gmtime_r needed" have_struct_member('struct tm', 'tm_gmtoff', 'time.h') have_func('rb_str_set_len', 'ruby.h') + have_func('rb_thread_call_without_gvl', 'ruby/thread.h') have_func('rb_thread_blocking_region', 'ruby.h') have_func('rb_thread_io_blocking_region', 'ruby.h') create_makefile('clogger_ext') -- 1.9.0.rc3.13.gda73b5f