From: Eric Wong <e@80x24.org>
To: raindrops-public@bogomips.org
Subject: [PATCH] Ruby thread compatibility updates
Date: Wed, 26 Apr 2017 01:10:59 +0000 [thread overview]
Message-ID: <20170426011059.17792-1-e@80x24.org> (raw)
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 <ruby.h>
#include <stdarg.h>
-#ifdef HAVE_RUBY_ST_H
-# include <ruby/st.h>
-#else
-# include <st.h>
-#endif
+#include <ruby/st.h>
#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 <rubysig.h>
-# 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 <ruby/thread.h>
+# 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 <assert.h>
#include <errno.h>
@@ -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
reply other threads:[~2017-04-26 1:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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: http://yhbt.net/raindrops/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170426011059.17792-1-e@80x24.org \
--to=e@80x24.org \
--cc=raindrops-public@bogomips.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
http://yhbt.net/raindrops.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).