From 484eaf30488bda6489a525b43fd106e4f1327eb5 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Thu, 19 Sep 2024 12:22:23 -0400 Subject: [PATCH 1/2] rb_thread_call_with_gvl is lenient when it has already acquired GVL --- thread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/thread.c b/thread.c index 5a79200785..0f5bfefe71 100644 --- a/thread.c +++ b/thread.c @@ -1868,6 +1868,9 @@ rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd) * created as Ruby thread (created by Thread.new or so). In other * words, this function *DOES NOT* associate or convert a NON-Ruby * thread to a Ruby thread. + * + * NOTE: If this thread has already aquired the GVL, then the method call + * is performed without acquiring or releasing the GVL. */ void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1) @@ -1891,7 +1894,8 @@ rb_thread_call_with_gvl(void *(*func)(void *), void *data1) prev_unblock = th->unblock; if (brb == 0) { - rb_bug("rb_thread_call_with_gvl: called by a thread which has GVL."); + /* the GVL is already acquired, call method directly */ + return (*func)(data1); } blocking_region_end(th, brb); -- 2.46.0