feat: add create Options, per-fiber data, and reset for pooling - #4
Merged
Conversation
Give Fiber a public data: ?*anyopaque payload and move create to an Options
struct (stack_size, data), so a scheduler can attach runtime task state to a
fiber without generating a function per task at comptime. Breaking: create now
takes an options argument; pass .{} for the previous defaults. Every in-repo
call site (examples and tests) is updated.
Re-arm a finished or never-started fiber with a new entry and data, reusing the same stack allocation, so a scheduler can maintain a fiber pool and recycle fibers between jobs instead of paying a stack allocation per job.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make
Fiberusable as the building block for a pooling scheduler: attach a per-fiber payload, choose the stack size, and recycle finished fibers without reallocating.Changes
datapayload — a publicdata: ?*anyopaque = nullfield onFiber, so a scheduler can associate a fiber with a runtime-created task instead of generating a function per task at comptime. Read it in the entry viafiber.data.createoptions (breaking) —create(allocator, entry, options: Options)whereOptions = struct { stack_size: usize = 64*1024, data: ?*anyopaque = null }. Pass.{}for the previous defaults. Every in-repo call site (examples + tests) is updated.resetfor reuse —reset(entry, data)re-arms a finished (or never-started) fiber with a new entry and data, reusing the same stack allocation (the pooling primitive). It reinitializes the stack viasetupStackand must not be called on a running or suspended fiber.Added+Changed) updated.Pure Zig — no inline assembly changed.
Related Issues
Test Plan
zig buildcompiles cleanlyzig build testpasses (14 tests, Windows) — including data-payload, custom-stack-size, and reset-reuse-with-suspend/resume testszig build examplesruns both exampleszig fmt --check .passesubuntu-latestandwindows-latest