Struct cros_async::Event
pub struct Event(pub(crate) PlatformEvent);
Expand description
An inter-process event wait/notify mechanism. Loosely speaking: Writes signal the event. Reads block until the event is signaled and then clear the signal.
Supports multiple simultaneous writers (i.e. signalers) but only one simultaneous reader (i.e. waiter). The behavior of multiple readers is undefined in cross platform code.
Multiple Event
s can be polled at once via WaitContext
.
Implementation notes:
- Uses eventfd on Linux.
- Uses synchapi event objects on Windows.
- The
Event
andWaitContext
APIs together cannot easily be implemented with the same semantics on all platforms. In particular, it is difficult to support multiple readers, so only a single reader is allowed for now. Multiple readers will result in undefined behavior.
Tuple Fields§
§0: PlatformEvent
Implementations§
§impl Event
impl Event
pub fn wait(&self) -> Result<(), Error>
pub fn wait(&self) -> Result<(), Error>
Blocks until the event is signaled and clears the signal.
It is undefined behavior to wait on an event from multiple threads or processes simultaneously.
pub fn wait_timeout(&self, timeout: Duration) -> Result<EventWaitResult, Error>
pub fn wait_timeout(&self, timeout: Duration) -> Result<EventWaitResult, Error>
Blocks until the event is signaled and clears the signal, or until the timeout duration expires.
It is undefined behavior to wait on an event from multiple threads or processes simultaneously.
pub fn reset(&self) -> Result<(), Error>
pub fn reset(&self) -> Result<(), Error>
Clears the event without blocking.
If the event is not signaled, this has no effect and returns immediately.
pub fn try_clone(&self) -> Result<Event, Error>
pub fn try_clone(&self) -> Result<Event, Error>
Clones the event. The event’s state is shared between cloned instances.
The documented caveats for Event
also apply to a set of cloned instances, e.g., it is
undefined behavior to clone an event and then call Event::wait
simultaneously on both
objects.
Implementation notes:
- Linux: The cloned instance uses a separate file descriptor.
- Windows: The cloned instance uses a separate handle.
Trait Implementations§
§impl AsRawDescriptor for Event
impl AsRawDescriptor for Event
§fn as_raw_descriptor(&self) -> i32
fn as_raw_descriptor(&self) -> i32
§impl<'de> Deserialize<'de> for Event
impl<'de> Deserialize<'de> for Event
§fn deserialize<__D>(
__deserializer: __D
) -> Result<Event, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Event, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl EventExt for Event
impl EventExt for Event
§fn write_count(&self, v: u64) -> Result<(), Error>
fn write_count(&self, v: u64) -> Result<(), Error>
v
to the eventfd’s count, blocking until this won’t overflow the count.