Skip to content

Commit bc9ea58

Browse files
Add rb_ec_close function to manage execution context cleanup. (ruby#15253)
1 parent 8eea9a5 commit bc9ea58

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

cont.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,7 @@ void
29072907
rb_fiber_close(rb_fiber_t *fiber)
29082908
{
29092909
fiber_status_set(fiber, FIBER_TERMINATED);
2910+
rb_ec_close(&fiber->cont.saved_ec);
29102911
}
29112912

29122913
static void

vm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,13 @@ rb_ec_clear_vm_stack(rb_execution_context_t *ec)
38903890
rb_ec_set_vm_stack(ec, NULL, 0);
38913891
}
38923892

3893+
void
3894+
rb_ec_close(rb_execution_context_t *ec)
3895+
{
3896+
// Fiber storage is not accessible from outside the running fiber, so it is safe to clear it here.
3897+
ec->storage = Qnil;
3898+
}
3899+
38933900
static void
38943901
th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
38953902
{

vm_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,10 @@ void rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t
11041104
// @param ec the execution context to update.
11051105
void rb_ec_clear_vm_stack(rb_execution_context_t *ec);
11061106

1107+
// Close an execution context and free related resources that are no longer needed.
1108+
// @param ec the execution context to close.
1109+
void rb_ec_close(rb_execution_context_t *ec);
1110+
11071111
struct rb_ext_config {
11081112
bool ractor_safe;
11091113
};

0 commit comments

Comments
 (0)