Struct sync42::wait_list::WaitGuard

source ·
pub struct WaitGuard<'a, T: Clone + 'a> { /* private fields */ }
Expand description

Callers link a Waiter into the list and protect it with a WaitGuard. The WaitGuard will panic if the caller fails to unlink.

Implementations§

source§

impl<'a, T: Clone + 'a> WaitGuard<'a, T>

source

pub fn iter<'b: 'a>(&'b self) -> WaitIterator<'b, T>

Iterate the list from our position forward.

source

pub fn index(&mut self) -> u64

Return our index into the list.

source

pub fn store(&mut self, t: T)

Store a value for the WaitGuard thread to load later.

source

pub fn load(&mut self) -> T

Load the value for the WaitGuard.

source

pub fn swap(&mut self, t: &mut T)

Swap with the current value.

source

pub fn is_head(&mut self) -> bool

True iff the thread is the lowest-index thread in the system.

source

pub fn count(&mut self) -> u64

Count how many threads are in the list. This should be used for debugging, not for logic.

source

pub fn get_waiter<'c, 'b: 'c>( &'b mut self, index: u64 ) -> Option<WaitGuard<'c, T>>

Use the WaitGuard provided by self to get a wait guard to a later position in the list. It is not possible to get a wait guard to an index less than our own position. This limitation enables us to enforce lifetimes with the borrow checker. Returns None if the owner called unlink on the index.

source

pub fn naked_wait<'b, M>(&self, guard: MutexGuard<'b, M>) -> MutexGuard<'b, M>

Atomically unlock the guard and wait on the internal condition variable.

source

pub fn wait_for_store<'b, M>( &self, guard: MutexGuard<'b, M> ) -> (MutexGuard<'b, M>, T)

Wait until someone stores a value in the guard. Note that you must always make sure that some other thread will call store on this wait guard’s index.

source

pub fn notify(&self)

Notify the waiter that it’s time to wake up.

Trait Implementations§

source§

impl<'a, T: Debug + Clone + 'a> Debug for WaitGuard<'a, T>

source§

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

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

impl<'a, T: Clone + 'a> Drop for WaitGuard<'a, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for WaitGuard<'a, T>

§

impl<'a, T> Send for WaitGuard<'a, T>
where T: Send,

§

impl<'a, T> Sync for WaitGuard<'a, T>
where T: Send,

§

impl<'a, T> Unpin for WaitGuard<'a, T>

§

impl<'a, T> UnwindSafe for WaitGuard<'a, T>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.