aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/-test-/gvl/call_without_gvl/call_without_gvl.c41
-rw-r--r--ext/zlib/zlib.c6
2 files changed, 45 insertions, 2 deletions
diff --git a/ext/-test-/gvl/call_without_gvl/call_without_gvl.c b/ext/-test-/gvl/call_without_gvl/call_without_gvl.c
index f3071d5768..654c979479 100644
--- a/ext/-test-/gvl/call_without_gvl/call_without_gvl.c
+++ b/ext/-test-/gvl/call_without_gvl/call_without_gvl.c
@@ -27,8 +27,49 @@ thread_runnable_sleep(VALUE thread, VALUE timeout)
return thread;
}
+struct loop_ctl {
+ int notify_fd;
+ volatile int stop;
+};
+
+static void *
+do_loop(void *p)
+{
+ struct loop_ctl *ctl = p;
+
+ /* tell the waiting process they can interrupt us, now */
+ write(ctl->notify_fd, "", 1);
+
+ while (!ctl->stop) {
+ struct timeval tv = { 0, 10000 };
+ select(0, NULL, NULL, NULL, &tv);
+ }
+ return 0;
+}
+
+static void
+stop_set(void *p)
+{
+ struct loop_ctl *ctl = p;
+
+ ctl->stop = 1;
+}
+
+static VALUE
+thread_ubf_async_safe(VALUE thread, VALUE notify_fd)
+{
+ struct loop_ctl ctl;
+
+ ctl.notify_fd = NUM2INT(notify_fd);
+ ctl.stop = 0;
+
+ rb_nogvl(do_loop, &ctl, stop_set, &ctl, RB_NOGVL_UBF_ASYNC_SAFE);
+ return thread;
+}
+
void
Init_call_without_gvl(void)
{
rb_define_method(rb_cThread, "__runnable_sleep__", thread_runnable_sleep, 1);
+ rb_define_method(rb_cThread, "__ubf_async_safe__", thread_ubf_async_safe, 1);
}
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 1b48bb2677..f1fd2b5c8a 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -1011,6 +1011,7 @@ zstream_run_func(void *ptr)
/*
* There is no safe way to interrupt z->run->func().
+ * async-signal-safe
*/
static void
zstream_unblock_func(void *ptr)
@@ -1053,8 +1054,9 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
}
loop:
- err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_func, (void *)&args,
- zstream_unblock_func, (void *)&args);
+ err = (int)(VALUE)rb_nogvl(zstream_run_func, (void *)&args,
+ zstream_unblock_func, (void *)&args,
+ RB_NOGVL_UBF_ASYNC_SAFE);
if (flush != Z_FINISH && err == Z_BUF_ERROR
&& z->stream.avail_out > 0) {