pub struct SharedCondvar { /* private fields */ }Expand description
Cross-process condition variable. Mesa-style: callers re-check
the predicate after each wake. Internally backed by one
CrossProcessWaker plus a generation counter in mmap.
Implementations§
Sourcepub fn create_anon() -> Result<Self, CondvarError>
pub fn create_anon() -> Result<Self, CondvarError>
In-process condvar (anonymous waker + anonymous mmap for the generation atom).
Sourcepub fn create_anon_with_capacity(
max_waiters: usize,
) -> Result<Self, CondvarError>
pub fn create_anon_with_capacity( max_waiters: usize, ) -> Result<Self, CondvarError>
In-process condvar with a custom max-waiters capacity.
Sourcepub fn create(base_path: impl AsRef<Path>) -> Result<Self, CondvarError>
pub fn create(base_path: impl AsRef<Path>) -> Result<Self, CondvarError>
File-backed condvar. Path layout:
<base>.waker.bin - waker slot array
<base>.gen.bin - magic + generation counter
pub fn create_with_capacity( base_path: impl AsRef<Path>, max_waiters: usize, ) -> Result<Self, CondvarError>
Sourcepub fn open(base_path: impl AsRef<Path>) -> Result<Self, CondvarError>
pub fn open(base_path: impl AsRef<Path>) -> Result<Self, CondvarError>
Open an existing file-backed condvar. Both processes that
share the condvar pass the same base_path; one calls
create, the other (and any later joiners) call open.
pub fn open_with_capacity( base_path: impl AsRef<Path>, expected_max_waiters: usize, ) -> Result<Self, CondvarError>
Sourcepub fn wait<F: FnMut() -> bool>(&self, predicate: F) -> Result<(), CondvarError>
pub fn wait<F: FnMut() -> bool>(&self, predicate: F) -> Result<(), CondvarError>
Park until predicate() returns true. Re-evaluates the
predicate after every wake (Mesa-style). Spurious wakes
re-loop without surfacing to the caller.
Sourcepub fn wait_timeout<F: FnMut() -> bool>(
&self,
predicate: F,
timeout: Duration,
) -> Result<(), CondvarError>
pub fn wait_timeout<F: FnMut() -> bool>( &self, predicate: F, timeout: Duration, ) -> Result<(), CondvarError>
Park until predicate() returns true OR timeout elapses.
On Err(Timeout) the predicate is guaranteed to have been
false at the point of return.
Sourcepub fn notify_one(&self) -> usize
pub fn notify_one(&self) -> usize
Wake at most one parked waiter. Caller is responsible for having advanced the predicate before calling. Returns 1 if a waiter was woken, 0 if none were parked.
Sourcepub fn notify_all(&self) -> usize
pub fn notify_all(&self) -> usize
Wake every parked waiter. Returns the count actually woken.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Current generation snapshot (observational; advances on every notify).
Sourcepub fn waker(&self) -> &Arc<CrossProcessWaker> ⓘ
pub fn waker(&self) -> &Arc<CrossProcessWaker> ⓘ
Underlying waker handle, for callers who want to peek wake state directly.