Struct seqlock::SeqLock

source ·
pub struct SeqLock<T> { /* private fields */ }
Expand description

A sequential lock

Implementations§

source§

impl<T: Copy> SeqLock<T>

source

pub const fn new(val: T) -> SeqLock<T>

Creates a new SeqLock with the given initial value.

source

pub fn read(&self) -> T

Reads the value protected by the SeqLock.

This operation is extremely fast since it only reads the SeqLock, which allows multiple readers to read the value without interfering with each other.

If a writer is currently modifying the contained value then the calling thread will block until the writer thread releases the lock.

Attempting to read from a SeqLock while already holding a write lock in the current thread will result in a deadlock.

source

pub fn lock_write(&self) -> SeqLockGuard<'_, T>

Locks this SeqLock with exclusive write access, blocking the current thread until it can be acquired.

This function does not block while waiting for concurrent readers. Instead, readers will detect the concurrent write and retry the read.

Returns an RAII guard which will drop the write access of this SeqLock when dropped.

source

pub fn try_lock_write(&self) -> Option<SeqLockGuard<'_, T>>

Attempts to lock this SeqLock with exclusive write access.

If the lock could not be acquired at this time, then None is returned. Otherwise, an RAII guard is returned which will release the lock when it is dropped.

This function does not block.

source

pub fn into_inner(self) -> T

Consumes this SeqLock, returning the underlying data.

source

pub fn get_mut(&mut self) -> &mut T

Returns a mutable reference to the underlying data.

Since this call borrows the SeqLock mutably, no actual locking needs to take place—the mutable borrow statically guarantees no locks exist.

Trait Implementations§

source§

impl<T: Copy + Debug> Debug for SeqLock<T>

source§

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

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

impl<T: Copy + Default> Default for SeqLock<T>

source§

fn default() -> SeqLock<T>

Returns the “default value” for a type. Read more
source§

impl<T: Send> Send for SeqLock<T>

source§

impl<T: Send> Sync for SeqLock<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SeqLock<T>

§

impl<T> Unpin for SeqLock<T>where T: Unpin,

§

impl<T> UnwindSafe for SeqLock<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.