summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@shopify.com>2025-12-01 17:49:31 +1300
committerGitHub <noreply@github.com>2025-12-01 04:49:31 +0000
commitbc9ea585bee075480b4f12f84c8ab99315766595 (patch)
tree4ba523578ddb34c478f702dcfe0e1eb960a5fc95
parent8eea9a502031e866f210accc7d02347fc55f65c9 (diff)
Add `rb_ec_close` function to manage execution context cleanup. (#15253)
-rw-r--r--cont.c1
-rw-r--r--vm.c7
-rw-r--r--vm_core.h4
3 files changed, 12 insertions, 0 deletions
diff --git a/cont.c b/cont.c
index c49256c977..50e8ffb349 100644
--- a/cont.c
+++ b/cont.c
@@ -2907,6 +2907,7 @@ void
rb_fiber_close(rb_fiber_t *fiber)
{
fiber_status_set(fiber, FIBER_TERMINATED);
+ rb_ec_close(&fiber->cont.saved_ec);
}
static void
diff --git a/vm.c b/vm.c
index f9c615c3e2..1a8a6d059b 100644
--- a/vm.c
+++ b/vm.c
@@ -3890,6 +3890,13 @@ rb_ec_clear_vm_stack(rb_execution_context_t *ec)
rb_ec_set_vm_stack(ec, NULL, 0);
}
+void
+rb_ec_close(rb_execution_context_t *ec)
+{
+ // Fiber storage is not accessible from outside the running fiber, so it is safe to clear it here.
+ ec->storage = Qnil;
+}
+
static void
th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
{
diff --git a/vm_core.h b/vm_core.h
index 28d585deb2..9d11457966 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -1104,6 +1104,10 @@ void rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t
// @param ec the execution context to update.
void rb_ec_clear_vm_stack(rb_execution_context_t *ec);
+// Close an execution context and free related resources that are no longer needed.
+// @param ec the execution context to close.
+void rb_ec_close(rb_execution_context_t *ec);
+
struct rb_ext_config {
bool ractor_safe;
};