summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/thread.c b/thread.c
index 06fd49cf2c..59935a2e1c 100644
--- a/thread.c
+++ b/thread.c
@@ -1421,9 +1421,10 @@ blocking_region_end(rb_thread_t *th, struct rb_blocking_region_buffer *region)
}
}
-static void *
-call_without_gvl(void *(*func)(void *), void *data1,
- rb_unblock_function_t *ubf, void *data2, int fail_if_interrupted)
+void *
+rb_nogvl(void *(*func)(void *), void *data1,
+ rb_unblock_function_t *ubf, void *data2,
+ int flags)
{
void *val = 0;
rb_execution_context_t *ec = GET_EC();
@@ -1436,15 +1437,22 @@ call_without_gvl(void *(*func)(void *), void *data1,
data2 = th;
}
else if (ubf && vm_living_thread_num(th->vm) == 1) {
- ubf_th = rb_thread_start_unblock_thread();
+ if (RB_NOGVL_UBF_ASYNC_SAFE) {
+ th->vm->ubf_async_safe = 1;
+ }
+ else {
+ ubf_th = rb_thread_start_unblock_thread();
+ }
}
BLOCKING_REGION(th, {
val = func(data1);
saved_errno = errno;
- }, ubf, data2, fail_if_interrupted);
+ }, ubf, data2, flags & RB_NOGVL_INTR_FAIL);
+
+ th->vm->ubf_async_safe = 0;
- if (!fail_if_interrupted) {
+ if ((flags & RB_NOGVL_INTR_FAIL) == 0) {
RUBY_VM_CHECK_INTS_BLOCKING(ec);
}
@@ -1546,14 +1554,14 @@ void *
rb_thread_call_without_gvl2(void *(*func)(void *), void *data1,
rb_unblock_function_t *ubf, void *data2)
{
- return call_without_gvl(func, data1, ubf, data2, TRUE);
+ return rb_nogvl(func, data1, ubf, data2, RB_NOGVL_INTR_FAIL);
}
void *
rb_thread_call_without_gvl(void *(*func)(void *data), void *data1,
rb_unblock_function_t *ubf, void *data2)
{
- return call_without_gvl(func, data1, ubf, data2, FALSE);
+ return rb_nogvl(func, data1, ubf, data2, 0);
}
VALUE