summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-03-30 02:50:51 +0900
committerKoichi Sasada <ko1@atdot.net>2023-03-30 14:56:23 +0900
commit94e41822679ebd269564ad10d366596e1514d4ef (patch)
tree0eda5149b52e3e8e038e51a960ab655cf81a2bd9
parentba72849a3f5d2369821dfecbb5bf60b9a0e7cd4e (diff)
`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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7617
-rw-r--r--ractor.c9
-rw-r--r--vm_core.h12
2 files changed, 14 insertions, 7 deletions
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)
{