Skip to main content

Event

Struct Event 

Source
pub struct Event { /* private fields */ }
Expand description

An owned event object.

Holds a handle to an event, shared by every clone, and closes it when the last clone drops. A clone is a second holder of the same handle, not a new handle: setting through one is seen through every other (WS-D-10). Because the handle is owned and is known to be an event, set and reset need no unsafe.

The handle being an event is what other crates may rely on (WS-D-4). Ownership alone keeps set memory-safe; it is event-ness that lets a consumer such as the thread pool, which cannot wait on a mutex, accept an Event without unsafe. That is why adopting an existing handle, from_owned_handle, is unsafe.

Setting and resetting take &self: they are atomic kernel operations, and an Event is Send and Sync. Setting an event that is already signalled changes nothing – an event is either signalled or not, and does not count how often it was set.

There is no pulse; see the crate documentation for why.

Implementations§

Source§

impl Event

Source

pub fn new(reset: ResetMode, initially_signalled: bool) -> Result<Event, Error>

Create an unnamed event.

§Errors

Returns the error from CreateEventW. No test reaches this path: creating an unnamed event fails only when the process cannot get another handle or the kernel cannot allocate the object, which a test can produce only by exhausting a resource the rest of the run needs.

Source

pub unsafe fn from_owned_handle(handle: OwnedHandle) -> Event

Adopt a handle the caller already owns as an event.

For an event that came from somewhere this crate did not create it, such as another library or a handle passed in by a parent process.

A handle without EVENT_MODIFY_STATE access is accepted: set and reset then report the access error rather than changing the event.

§Safety

The caller guarantees that handle:

  • refers to an event object – not a mutex, a semaphore or any other kind, because code holding an Event may rely on that; and
  • carries SYNCHRONIZE access, so that anything given the Event to wait on can wait on it. What a thread-pool wait does with a handle it cannot wait on is not documented, and an Event must be safe to hand it.
Source

pub fn set(&self) -> Result<(), Error>

Set the event to signalled.

Releases one waiter if the event is ResetMode::Auto, and every waiter until it is reset if it is ResetMode::Manual. Setting an event that is already signalled succeeds and changes nothing.

§Errors

Returns the error from SetEvent: an access-denied error when the handle was adopted without EVENT_MODIFY_STATE.

Source

pub fn reset(&self) -> Result<(), Error>

Set the event to unsignalled.

Resetting an event that is already unsignalled succeeds and changes nothing. Resetting an auto-reset event withdraws a signal no waiter has taken yet.

§Errors

Returns the error from ResetEvent: an access-denied error when the handle was adopted without EVENT_MODIFY_STATE.

Source

pub fn try_into_owned(self) -> Result<OwnedHandle, Event>

The handle, as an OwnedHandle, if self is its last holder.

§Errors

If a clone still holds the handle, returns self unchanged, so nothing is lost and the caller can try again once the clones have dropped.

Source

pub fn duplicate_wait_only(&self) -> Result<WaitOnlyEvent, Error>

A new handle to the same event that can wait on it and do nothing else: the one operation here that makes a handle, because access belongs to a handle and narrowing it needs a new one (WS-D-10).

The handle carries SYNCHRONIZE access alone, so it can neither set nor reset the event: the kernel refuses a SetEvent or ResetEvent on it. A clone cannot give that, since it shares the original’s handle and so its access. See WaitOnlyEvent for what the result is, why it is not an Event, and what the guarantee does not cover.

A wait through it takes what a signalled event gives, as any wait does: waiting through a wait-only handle consumes an auto-reset event’s signal. What it cannot do is signal or withdraw one.

§Errors

Returns the error from DuplicateHandle. Like new’s, no test reaches it: duplicating a handle this process owns fails only when the process cannot get another handle.

Trait Implementations§

Source§

impl AsHandle for Event

Source§

fn as_handle(&self) -> BorrowedHandle<'_>

Borrows the handle. Read more
Source§

impl AsRawHandle for Event

Source§

fn as_raw_handle(&self) -> *mut c_void

Extracts the raw handle. Read more
Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<Event> for SharedHandle

The shared handle, given up by this holder: what a consumer that holds handles shared, such as the thread pool’s wait target, takes.

Source§

fn from(event: Event) -> SharedHandle

Converts to this type from the input type.
Source§

impl Signalable for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.