Skip to content

Commit

Permalink
Fix exception handling in rb_fiber_scheduler_set. (ruby#10042)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Feb 21, 2024
1 parent 78d9fe6 commit 04729fe
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ verify_interface(VALUE scheduler)
}
}

static VALUE
fiber_scheduler_close(VALUE scheduler)
{
return rb_fiber_scheduler_close(scheduler);
}

static VALUE
fiber_scheduler_close_ensure(VALUE _thread)
{
rb_thread_t *thread = (rb_thread_t*)_thread;
thread->scheduler = Qnil;

return Qnil;
}

VALUE
rb_fiber_scheduler_set(VALUE scheduler)
{
Expand All @@ -178,7 +193,8 @@ rb_fiber_scheduler_set(VALUE scheduler)
// That way, we do not need to consider interactions, e.g., of a Fiber from
// the previous scheduler with the new scheduler.
if (thread->scheduler != Qnil) {
rb_fiber_scheduler_close(thread->scheduler);
// rb_fiber_scheduler_close(thread->scheduler);
rb_ensure(fiber_scheduler_close, thread->scheduler, fiber_scheduler_close_ensure, (VALUE)thread);
}

thread->scheduler = scheduler;
Expand Down

0 comments on commit 04729fe

Please sign in to comment.