From: Hleb Valoshka <375gnu@gmail.com>
To: kgio@librelist.org
Subject: [PATCH] Don't use deprecated api
Date: Thu, 26 Dec 2013 22:57:07 +0300 [thread overview]
Message-ID: <1388087827-13015-1-git-send-email-375GNU@Gmail.COM> (raw)
In-Reply-To: <1388087827-13015-1-git-send-email-375GNU@Gmail.COM>
This patch allows to use current Ruby API (rb_thread_call_without_gvl)
instead of deprecated `rb_thread_blocking_region'.
---
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(-)
diff --git a/ext/kgio/accept.c b/ext/kgio/accept.c
index 67a8ded..ebfcf54 100644
--- a/ext/kgio/accept.c
+++ b/ext/kgio/accept.c
@@ -10,7 +10,9 @@ 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(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
# include <time.h>
# include "blocking_io_region.h"
static int thread_accept(struct accept_args *a, int force_nonblock)
diff --git a/ext/kgio/blocking_io_region.h b/ext/kgio/blocking_io_region.h
index 30c7106..2a17c05 100644
--- a/ext/kgio/blocking_io_region.h
+++ b/ext/kgio/blocking_io_region.h
@@ -6,4 +6,7 @@ VALUE rb_thread_io_blocking_region(rb_blocking_function_t *, void *, int);
# define rb_thread_io_blocking_region(fn,data,fd) \
rb_thread_blocking_region((fn),(data),RUBY_UBF_IO,0)
# endif
+#else
+# define rb_thread_io_blocking_region(fn,data,fd) \
+ rb_thread_call_without_gvl((fn),(data),RUBY_UBF_IO,0)
#endif
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
have_func('rb_str_set_len')
have_func('rb_time_interval')
have_func('rb_wait_for_single_fd')
diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
index 902c745..bcf443d 100644
--- a/ext/kgio/tryopen.c
+++ b/ext/kgio/tryopen.c
@@ -38,7 +38,7 @@ static VALUE nogvl_open(void *ptr)
return (VALUE)rb_cloexec_open(o->pathname, o->flags, o->mode);
}
-#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
if (fd < 0) {
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
rb_gc();
--
1.8.5.2
next parent reply other threads:[~2013-12-26 19:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-26 19:57 Hleb Valoshka [this message]
2013-12-27 0:19 ` [PATCH] Don't use deprecated api Eric Wong
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=1388087827-13015-1-git-send-email-375GNU@Gmail.COM \
--to=375gnu@gmail.com \
--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).