Skip to content

Commit 2f97734

Browse files
Pass quantum to fiber_initialize instead of setting it after the call
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1cb3b8d commit 2f97734

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

cont.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ rb_fiber_storage_aset(VALUE class, VALUE key, VALUE value)
23692369
}
23702370

23712371
static VALUE
2372-
fiber_initialize(VALUE self, VALUE proc, struct fiber_pool * fiber_pool, unsigned int blocking, VALUE storage)
2372+
fiber_initialize(VALUE self, VALUE proc, struct fiber_pool * fiber_pool, unsigned int blocking, VALUE storage, VALUE quantum)
23732373
{
23742374
if (storage == Qundef || storage == Qtrue) {
23752375
// The default, inherit storage (dup) from the current fiber:
@@ -2387,6 +2387,12 @@ fiber_initialize(VALUE self, VALUE proc, struct fiber_pool * fiber_pool, unsigne
23872387
fiber->stack.base = NULL;
23882388
fiber->stack.pool = fiber_pool;
23892389

2390+
if (!UNDEF_P(quantum)) {
2391+
uint32_t q = NUM2UINT(quantum);
2392+
if (q == 0) rb_raise(rb_eArgError, "quantum must be positive");
2393+
fiber->cont.saved_ec.quantum = q;
2394+
}
2395+
23902396
return self;
23912397
}
23922398

@@ -2450,15 +2456,7 @@ rb_fiber_initialize_kw(int argc, VALUE* argv, VALUE self, int kw_splat)
24502456
quantum = arguments[3];
24512457
}
24522458

2453-
fiber_initialize(self, rb_block_proc(), rb_fiber_pool_default(pool), RTEST(blocking), storage);
2454-
2455-
if (!UNDEF_P(quantum)) {
2456-
uint32_t q = NUM2UINT(quantum);
2457-
if (q == 0) rb_raise(rb_eArgError, "quantum must be positive");
2458-
fiber_ptr(self)->cont.saved_ec.quantum = q;
2459-
}
2460-
2461-
return self;
2459+
return fiber_initialize(self, rb_block_proc(), rb_fiber_pool_default(pool), RTEST(blocking), storage, quantum);
24622460
}
24632461

24642462
/*
@@ -2519,7 +2517,7 @@ rb_fiber_initialize(int argc, VALUE* argv, VALUE self)
25192517
VALUE
25202518
rb_fiber_new_storage(rb_block_call_func_t func, VALUE obj, VALUE storage)
25212519
{
2522-
return fiber_initialize(fiber_alloc(rb_cFiber), rb_proc_new(func, obj), rb_fiber_pool_default(Qnil), 0, storage);
2520+
return fiber_initialize(fiber_alloc(rb_cFiber), rb_proc_new(func, obj), rb_fiber_pool_default(Qnil), 0, storage, Qundef);
25232521
}
25242522

25252523
VALUE

0 commit comments

Comments
 (0)