about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-04-05 20:36:37 +0000
committerEric Wong <normalperson@yhbt.net>2013-04-05 22:30:07 +0000
commitece3095074fb5cf8c09d489f311ad990a4e0076b (patch)
treef7375d26e3290d42b2133ded3cff3e7c3a49bab5
parentbefa6dade6158a86be88c7580a6259059e20fb25 (diff)
downloadmahoro-ece3095074fb5cf8c09d489f311ad990a4e0076b.tar.gz
split out nogvl_compat header
This file may be used by other extensions, so make it easy
to share.
-rw-r--r--mahoro.c50
-rw-r--r--nogvl_compat.h54
2 files changed, 55 insertions, 49 deletions
diff --git a/mahoro.c b/mahoro.c
index 1c0b992..71be82a 100644
--- a/mahoro.c
+++ b/mahoro.c
@@ -8,6 +8,7 @@
 
 #include <ruby.h>
 #include <magic.h>
+#include "nogvl_compat.h"
 
 #ifndef RSTRING_LEN
 #  define RSTRING_LEN(s)->len
@@ -28,55 +29,6 @@ struct nogvl_args {
         } as;
 };
 
-/*
- * Compatibility layer for various GVL-releasing
- *
- * rb_thread_call_without_gvl was detectable via have_func in 1.9.3,
- * but not usable.  So we must check for ruby/thread.h and use
- * rb_thread_blocking_region if ruby/thread.h is not available
- *
- * HAVE_RUBY_THREAD_H is defined by ruby.h in 2.0.0, NOT using
- * extconf.rb since that may find ruby/thread.h in a different
- * installation
- */
-#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \
-        defined(HAVE_RUBY_THREAD_H) &&  \
-        HAVE_RUBY_THREAD_H
-#  include <ruby/thread.h>
-#  define NOGVL(fn,data1,ubf,data2) \
-      rb_thread_call_without_gvl((fn),(data1),(ubf),(data2))
-#elif defined(HAVE_RB_THREAD_BLOCKING_REGION) /* Ruby 1.9.x */
-#  define COMPAT_FN (VALUE (*)(void *))
-#  define NOGVL(fn,data1,ubf,data2) \
-      (void *)rb_thread_blocking_region(COMPAT_FN(fn),(data1),(ubf),(data2))
-#else /* Ruby 1.8 */
-/*
- * Ruby 1.8 does not have a GVL, we'll just enable signal interrupts
- * here in case we make interruptible syscalls
- */
-#  define RUBY_UBF_IO ((rb_unblock_function_t *)-1)
-#  include "rubysig.h"
-typedef void rb_unblock_function_t(void *);
-typedef void *rb_blocking_function_t(void *);
-
-static void *
-fake_nogvl(fn, data1, ubf, data2)
-        rb_blocking_function_t fn;
-        void *data1;
-        rb_unblock_function_t ubf;
-        void *data2;
-{
-        void *rv;
-
-        TRAP_BEG;
-        rv = fn(data1);
-        TRAP_END;
-
-        return rv;
-}
-#  define NOGVL(fn,data1,ubf,data2) fake_nogvl((fn),(data1),(ubf),(data2))
-#endif
-
 /* :nodoc: called automatically by GC */
 static void
 mahoro_free(ptr)
diff --git a/nogvl_compat.h b/nogvl_compat.h
new file mode 100644
index 0000000..c5b6778
--- /dev/null
+++ b/nogvl_compat.h
@@ -0,0 +1,54 @@
+#ifndef NOGVL_COMPAT_H
+#define NOGVL_COMPAT_H
+/*
+ * Compatibility layer for various GVL-releasing wrappers.
+ *
+ * This layer will be updated to favor compatibility with the latest
+ * Matz Ruby C API, currently Ruby 2.0.0 (as of 2013-04-05).
+ *
+ * rb_thread_call_without_gvl was detectable via have_func in 1.9.3,
+ * but not usable.  So we must check for ruby/thread.h and use
+ * rb_thread_blocking_region if ruby/thread.h is not available
+ *
+ * HAVE_RUBY_THREAD_H is defined by ruby.h in 2.0.0, NOT using
+ * extconf.rb since that may find ruby/thread.h in a different
+ * installation
+ */
+#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \
+        defined(HAVE_RUBY_THREAD_H) && HAVE_RUBY_THREAD_H /* Ruby 2.0.0 */
+#  include <ruby/thread.h>
+#  define NOGVL(fn,data1,ubf,data2) \
+      rb_thread_call_without_gvl((fn),(data1),(ubf),(data2))
+#elif defined(HAVE_RB_THREAD_BLOCKING_REGION) /* Ruby 1.9.x */
+#  define COMPAT_FN (VALUE (*)(void *))
+#  define NOGVL(fn,data1,ubf,data2) \
+      (void *)rb_thread_blocking_region(COMPAT_FN(fn),(data1),(ubf),(data2))
+#else /* Ruby 1.8 */
+/*
+ * Ruby 1.8 does not have a GVL, we'll just enable signal interrupts
+ * here in case we make interruptible syscalls
+ */
+#  define RUBY_UBF_IO ((rb_unblock_function_t *)-1)
+#  include "rubysig.h"
+typedef void rb_unblock_function_t(void *);
+typedef void *rb_blocking_function_t(void *);
+
+static void *
+fake_nogvl(fn, data1, ubf, data2)
+        rb_blocking_function_t fn;
+        void *data1;
+        rb_unblock_function_t ubf;
+        void *data2;
+{
+        void *rv;
+
+        TRAP_BEG;
+        rv = fn(data1);
+        TRAP_END;
+
+        return rv;
+}
+#  define NOGVL(fn,data1,ubf,data2) fake_nogvl((fn),(data1),(ubf),(data2))
+#endif
+
+#endif /* NOGVL_COMPAT_H */