summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorKeenan Brock <keenan@thebrocks.net>2024-09-26 16:34:39 -0400
committerBenoit Daloze <eregontp@gmail.com>2025-12-05 20:50:00 +0100
commit2b057859414d1ccfa4d88a898d27defc8c74dc1c (patch)
tree47aa3935cc1c99323f506973e2c4c14628c411d1 /thread.c
parent8c4f79d5f30fb2fe647c4f3fd262a5fdeacaeca2 (diff)
Allow rb_thread_call_with_gvl() to work when thread already has GVL
[Feature #20750] Co-authored-by: Benoit Daloze <eregontp@gmail.com>
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/thread.c b/thread.c
index 5f592a4256..7c88c97902 100644
--- a/thread.c
+++ b/thread.c
@@ -2042,6 +2042,9 @@ rb_thread_io_blocking_region(struct rb_io *io, rb_blocking_function_t *func, voi
* 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 acquired the GVL, then the method call
+ * is performed without acquiring or releasing the GVL (from Ruby 4.0).
*/
void *
rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
@@ -2065,7 +2068,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);