kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] Don't use deprecated api
@ 2013-12-26 19:57 Hleb Valoshka
  2013-12-27  0:19 ` Eric Wong
  2014-01-16 23:56 ` Eric Wong
  0 siblings, 2 replies; 9+ messages in thread
From: Hleb Valoshka @ 2013-12-26 19:57 UTC (permalink / raw)
  To: kgio


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



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-01-20 21:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-26 19:57 [PATCH] Don't use deprecated api Hleb Valoshka
2013-12-27  0:19 ` 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

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).