Repository navigation
Add ResetEvent synchronization primitive - #10
Conversation
Implements zio.ResetEvent similar to std.Thread.ResetEvent but adapted for coroutine-based runtime. Features atomic state management with CAS-based set() operation, wait queue for blocked coroutines, and timeout support. - Add ResetEvent struct with atomic state and wait queue - Implement core methods: init, isSet, set, reset, wait, timedWait - Use compare-and-swap in set() to ensure only winner wakes waiters - Add comprehensive tests covering all functionality - Export ResetEvent through main zio module
WalkthroughAdds .gitignore entries and introduces a public ResetEvent concurrency primitive (init, isSet, set, reset, wait, timedWait with timeout via xev timer). Re-exports ResetEvent from Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant RE as ResetEvent
participant WQ as WaitQueue
participant RT as Runtime
participant XT as xev Timer
rect rgba(230,240,255,0.35)
Caller->>RE: wait()
alt isSet fast-path
RE-->>Caller: return
else not set
RE->>WQ: enqueue(caller task)
RE->>RT: suspend(task)
note right of RT: task parked
end
end
rect rgba(235,255,235,0.35)
Caller->>RE: set()
RE->>RE: CAS unset -> set
RE->>WQ: wake all waiters
WQ->>RT: resume(waiters)
RT-->>Caller: continue
end
sequenceDiagram
autonumber
actor Caller
participant RE as ResetEvent
participant WQ as WaitQueue
participant RT as Runtime
participant XT as xev Timer
Caller->>RE: timedWait(timeout_ns)
alt isSet fast-path
RE-->>Caller: return
else not set
RE->>WQ: enqueue(caller task)
RE->>XT: arm timer(timeout_ns)
RE->>RT: suspend(task)
end
alt Event set before timeout
RE->>WQ: wake all
WQ->>RT: resume(task)
XT-->>XT: cancel timer
RT-->>Caller: return
else Timeout fires
XT-->>RT: timeout for task
RT-->>Caller: error Timeout
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Implements three-state model to eliminate race between checking state and registering as waiter. Uses atomic CAS to register waiters and swap() in set() to atomically determine if waiters need waking. States: - unset (0): Event not set, no waiters - waiting (1): Event not set, coroutines waiting - is_set (2): Event is set Changes: - wait()/timedWait() use CAS unset→waiting to atomically register - set() uses swap() to atomically set state and detect waiters - Eliminates gap where set() can miss waiters during registration - Adds comprehensive documentation matching std.Thread.ResetEvent
* Try to optimize CI * Optimize CI workflow to reduce VM overhead Split CI into separate build and test jobs. Build jobs cross-compile test binaries and upload as artifacts. VM test jobs download artifacts instead of copying entire workspace (~500MB+ including Zig installation). This fixes NetBSD VM hangs caused by excessive file copying and speeds up FreeBSD VM tests. VMs now only transfer ~2-5MB of test binaries. Also consolidates multiple backend tests per platform (epoll+poll on Linux, kqueue+poll on macOS/FreeBSD, kqueue+epoll on NetBSD). * Remove QEMU test jobs from CI QEMU tests for aarch64 and riscv64 are not needed for this project. * Fix NetBSD to test kqueue and poll instead of epoll epoll is Linux-specific and not available on NetBSD. NetBSD should test kqueue (native) and poll (POSIX fallback).
* Separate guard page check from uncommitted region in signal handler This makes the logic clearer by explicitly distinguishing between: - Guard page faults (true stack overflow, always abort) - Uncommitted region faults (automatic stack growth) * Improve stack overflow error messages with detailed diagnostics The error message now includes: - Fault address - Stack base address - Total stack size - Currently committed size - Whether fault was in guard page This makes debugging stack overflow issues much easier. * Fix exports
Summary
Features
API
init(runtime)- Initialize with runtime referenceisSet()- Check if event is set (atomic load with acquire ordering)set()- Mark event as set using CAS, wake all waitersreset()- Clear the set statewait()- Block until event is settimedWait(timeout_ns)- Block with timeoutTest plan
zig build testSummary by CodeRabbit
New Features
Chores