rb_current_ractor_raw(b)
`rb_current_ractor()` expects it has valid `ec` and `r`. `rb_current_ractor_raw()` with a parameter `false` allows to return NULL if `ec` is not available.
This commit is contained in:
parent
ba72849a3f
commit
94e4182267
Notes:
git
2023-03-30 05:56:44 +00:00
9
ractor.c
9
ractor.c
@ -61,18 +61,19 @@ ASSERT_ractor_locking(rb_ractor_t *r)
|
|||||||
static void
|
static void
|
||||||
ractor_lock(rb_ractor_t *r, const char *file, int line)
|
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);
|
ASSERT_ractor_unlocking(r);
|
||||||
rb_native_mutex_lock(&r->sync.lock);
|
rb_native_mutex_lock(&r->sync.lock);
|
||||||
|
|
||||||
#if RACTOR_CHECK_MODE > 0
|
#if RACTOR_CHECK_MODE > 0
|
||||||
if (rb_current_execution_context(false) != NULL) { // GET_EC is NULL in an RJIT worker
|
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
|
#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
|
static void
|
||||||
@ -94,7 +95,7 @@ ractor_unlock(rb_ractor_t *r, const char *file, int line)
|
|||||||
#endif
|
#endif
|
||||||
rb_native_mutex_unlock(&r->sync.lock);
|
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
|
static void
|
||||||
|
12
vm_core.h
12
vm_core.h
@ -1876,17 +1876,23 @@ rb_current_thread(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline rb_ractor_t *
|
static inline rb_ractor_t *
|
||||||
rb_current_ractor(void)
|
rb_current_ractor_raw(bool expect)
|
||||||
{
|
{
|
||||||
if (ruby_single_main_ractor) {
|
if (ruby_single_main_ractor) {
|
||||||
return ruby_single_main_ractor;
|
return ruby_single_main_ractor;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const rb_execution_context_t *ec = GET_EC();
|
const rb_execution_context_t *ec = rb_current_execution_context(expect);
|
||||||
return rb_ec_ractor_ptr(ec);
|
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 *
|
static inline rb_vm_t *
|
||||||
rb_current_vm(void)
|
rb_current_vm(void)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user