Skip to main content

RwLock

Struct RwLock 

Source
pub struct RwLock<T>(/* private fields */);
Expand description

Reader-writer lock backed by a futex.

Drop-in replacement for parking_lot::RwLock<T>. Non-fair: new readers are not blocked by waiting writers.

Additional methods beyond parking_lot:

  • is_locked_exclusive() — true when a write lock is held
  • get_n_waiters() — number of threads waiting (read + write)
  • reader_count() — number of active readers

Implementations§

Source§

impl<T> RwLock<T>

Source

pub fn new(val: T) -> Self

Creates a new RwLock wrapping val.

Source

pub fn read(&self) -> RwLockReadGuard<'_, T>

Acquires a shared (read) lock, blocking until available.

Source

pub fn write(&self) -> RwLockWriteGuard<'_, T>

Acquires an exclusive (write) lock, blocking until available.

Source

pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>>

Tries to acquire a shared lock without blocking.

Source

pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>>

Tries to acquire an exclusive lock without blocking.

Source

pub fn try_read_for(&self, timeout: Duration) -> Option<RwLockReadGuard<'_, T>>

Tries to acquire a shared lock within the given timeout.

Source

pub fn try_write_for( &self, timeout: Duration, ) -> Option<RwLockWriteGuard<'_, T>>

Tries to acquire an exclusive lock within the given timeout.

Source

pub fn is_locked(&self) -> bool

Returns true if the lock is held by any reader or by the exclusive writer.

Source

pub fn is_locked_exclusive(&self) -> bool

Returns true if the write (exclusive) lock is currently held.

Source

pub fn get_n_waiters(&self) -> usize

Returns the total number of threads waiting to acquire this lock.

Source

pub fn reader_count(&self) -> u32

Returns the number of active readers.

Source

pub fn raw(&self) -> &NoxuRawRwLock

Returns a reference to the raw NoxuRawRwLock.

Auto Trait Implementations§

§

impl<T> !Freeze for RwLock<T>

§

impl<T> !RefUnwindSafe for RwLock<T>

§

impl<T> Send for RwLock<T>
where T: Send,

§

impl<T> Sync for RwLock<T>
where T: Send + Sync,

§

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

§

impl<T> UnsafeUnpin for RwLock<T>
where T: UnsafeUnpin,

§

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

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>,

Source§

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>,

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.