* [PATCH 6/6] use rb_thread_call_without_gvl for Ruby 2+
@ 2014-02-15 23:09 7% ` Eric Wong
0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2014-02-15 23:09 UTC (permalink / raw)
To: clogger
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 <ruby/thread.h>
+# 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
^ permalink raw reply related [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2014-02-15 23:09 [PATCH 1/6] blocking_helpers: remove fstat wrapper Eric Wong
2014-02-15 23:09 7% ` [PATCH 6/6] use rb_thread_call_without_gvl for Ruby 2+ Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/clogger.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).