kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: kgio@librelist.org
Subject: Re: [PATCH] Don't use deprecated api
Date: Fri, 27 Dec 2013 00:19:57 +0000	[thread overview]
Message-ID: <20131227001957.GA24974@dcvr.yhbt.net> (raw)
In-Reply-To: 1388087827-13015-1-git-send-email-375GNU@Gmail.COM

Hleb Valoshka <375gnu@gmail.com> wrote:
> This patch allows to use current Ruby API (rb_thread_call_without_gvl)
> instead of deprecated `rb_thread_blocking_region'.

Thanks. I agree in principle, but the implementation needs to be
tweaked.  Comments inline.

>  ext/kgio/accept.c             | 7 +++++--
>  ext/kgio/blocking_io_region.h | 3 +++
>  ext/kgio/extconf.rb           | 8 ++++++--
>  ext/kgio/tryopen.c            | 6 +++++-
>  4 files changed, 19 insertions(+), 5 deletions(-)

connect.c needs to be updated for the MSG_FASTOPEN code.
I can do it if you can't test TFO on your system

>  static VALUE mSocketMethods;
>  static VALUE iv_kgio_addr;
>  
> -#if defined(__linux__) && defined(HAVE_RB_THREAD_BLOCKING_REGION)
> +#if defined(__linux__) && \
> +    (defined(HAVE_RB_THREAD_BLOCKING_REGION) || \
> +     defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
>  static int accept4_flags = SOCK_CLOEXEC;
>  #else /* ! linux */
>  static int accept4_flags = SOCK_CLOEXEC | SOCK_NONBLOCK;
> @@ -76,7 +78,8 @@ static VALUE xaccept(void *ptr)
>  	return (VALUE)rv;
>  }
>  
> -#ifdef HAVE_RB_THREAD_BLOCKING_REGION
> +#if defined HAVE_RB_THREAD_BLOCKING_REGION || \
> +    defined HAVE_RB_THREAD_CALL_WITHOUT_GVL

We should probably have a KGIO_ macro for both of these combined, so
it'll be harder to miss pieces like connect.c

> diff --git a/ext/kgio/extconf.rb b/ext/kgio/extconf.rb
> index 5fb15ac..eaf1af2 100644
> --- a/ext/kgio/extconf.rb
> +++ b/ext/kgio/extconf.rb
> @@ -46,8 +46,12 @@ have_func('rb_io_ascii8bit_binmode')
>  have_func('rb_update_max_fd')
>  have_func('rb_fd_fix_cloexec')
>  have_func('rb_cloexec_open')
> -have_func('rb_thread_blocking_region')
> -have_func('rb_thread_io_blocking_region')
> +if have_header('ruby/thread.h')
> +  have_func('rb_thread_call_without_gvl')
> +else
> +  have_func('rb_thread_blocking_region')
> +  have_func('rb_thread_io_blocking_region')
> +end

Even though rb_thread_io_blocking_region is not officially in the public
API, it is superior when an FD is known as it allows blocked threads
to be woken/interrupted on IO#close The socket stdlib uses it (as does
all the core IO methods).


We should check for all of these rb_thread_* functions unconditionally,
since sometimes these HAVE_* macros may be defined in headers regardless
of what we do in extconf.rb, so we shouldn't remove/change existing
checks for HAVE_* macros:

> -#ifndef HAVE_RB_THREAD_BLOCKING_REGION
> +#if !defined HAVE_RB_THREAD_BLOCKING_REGION && !defined RUBY_UBF_IO
>  #  define RUBY_UBF_IO ((void *)(-1))
>  #  include "rubysig.h"
>  typedef void rb_unblock_function_t(void *);


> @@ -105,7 +105,11 @@ static VALUE s_tryopen(int argc, VALUE *argv, VALUE klass)
>  	}
 
>  retry:
> +#ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
> +	fd = (int)rb_thread_call_without_gvl(nogvl_open, &o, RUBY_UBF_IO, 0);
> +#else
>  	fd = (int)rb_thread_blocking_region(nogvl_open, &o, RUBY_UBF_IO, 0);
> +#endif

Please define a wrapper macro, I intensely dislike #ifdef inside
function bodies.  I cannot stand reading some MRI code because of this;
my preferred C style is from the Linux kernel
(Documentation/CodingStyle).


  reply	other threads:[~2013-12-27  0:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-26 19:57 [PATCH] Don't use deprecated api Hleb Valoshka
2013-12-27  0:19 ` Eric Wong [this message]
2014-01-16 23:56 ` Eric Wong
2014-01-17  8:37   ` Hleb Valoshka
2014-01-19 19:42     ` Hleb Valoshka
2014-01-19 23:13       ` Eric Wong
2014-01-20 19:35         ` Hleb Valoshka
2014-01-20 19:36           ` Hleb Valoshka
2014-01-20 21:12             ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/kgio/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131227001957.GA24974@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=kgio@librelist.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kgio.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).