Trait uchan::Event

source ·
pub unsafe trait Event: Sync {
    fn with(f: impl FnOnce(Pin<&Self>));
    fn wait(self: Pin<&Self>);
    fn set(self: Pin<&Self>);
}
Expand description

An Event represents a single-producer, single-consumer notification synchronization primitive. A thread creates an Event using Event::with, makes it available to the producer, and uses Event::wait to block the caller thread until Event::set is called from another thread or from the same consumer thread prior to Event::wait.

The same thread which call Event::with will always be the same thread that waits. Event::set will also only be called by a single other “producer” thread, allowing for implementations to rely on any SPSC-style optimizations. Events are Pinned in case the implementation requires a stable address or utilizes intrusive memory.

Safety

Event::with must block until Event::set is called. Failure to uphold this invariant could result in undefined behavior at safe use sites.

Required Methods

Construct a pinned Event, allowing the closure to call wait on the Event reference.

Blocks the caller until the another thread (or previously on the same thread) invokes Event::set.

Marks the thread as active and unblocks the waiting thread if any. Further attempts to call Event::wait should return immediately.

Implementors