diff --git a/ractor.c b/ractor.c index b56f020586..23b3ca98f3 100644 --- a/ractor.c +++ b/ractor.c @@ -61,18 +61,19 @@ ASSERT_ractor_locking(rb_ractor_t *r) static void ractor_lock(rb_ractor_t *r, const char *file, int line) { - RUBY_DEBUG_LOG2(file, line, "locking r:%u%s", r->pub.id, GET_RACTOR() == r ? " (self)" : ""); + RUBY_DEBUG_LOG2(file, line, "locking r:%u%s", r->pub.id, rb_current_ractor_raw(false) == r ? " (self)" : ""); ASSERT_ractor_unlocking(r); rb_native_mutex_lock(&r->sync.lock); #if RACTOR_CHECK_MODE > 0 if (rb_current_execution_context(false) != NULL) { // GET_EC is NULL in an RJIT worker - r->sync.locked_by = rb_ractor_self(GET_RACTOR()); + rb_ractor_t *cr = rb_current_ractor_raw(false); + r->sync.locked_by = cr ? rb_ractor_self(cr) : Qundef; } #endif - RUBY_DEBUG_LOG2(file, line, "locked r:%u%s", r->pub.id, GET_RACTOR() == r ? " (self)" : ""); + RUBY_DEBUG_LOG2(file, line, "locked r:%u%s", r->pub.id, rb_current_ractor_raw(false) == r ? " (self)" : ""); } static void @@ -94,7 +95,7 @@ ractor_unlock(rb_ractor_t *r, const char *file, int line) #endif rb_native_mutex_unlock(&r->sync.lock); - RUBY_DEBUG_LOG2(file, line, "r:%u%s", r->pub.id, GET_RACTOR() == r ? " (self)" : ""); + RUBY_DEBUG_LOG2(file, line, "r:%u%s", r->pub.id, rb_current_ractor_raw(false) == r ? " (self)" : ""); } static void diff --git a/vm_core.h b/vm_core.h index 43e95a5dbe..2d5ec6f717 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1876,17 +1876,23 @@ rb_current_thread(void) } static inline rb_ractor_t * -rb_current_ractor(void) +rb_current_ractor_raw(bool expect) { if (ruby_single_main_ractor) { return ruby_single_main_ractor; } else { - const rb_execution_context_t *ec = GET_EC(); - return rb_ec_ractor_ptr(ec); + const rb_execution_context_t *ec = rb_current_execution_context(expect); + return (expect || ec) ? rb_ec_ractor_ptr(ec) : NULL; } } +static inline rb_ractor_t * +rb_current_ractor(void) +{ + return rb_current_ractor_raw(true); +} + static inline rb_vm_t * rb_current_vm(void) {