RwLock

Struct RwLock 

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

An efficient reader-writer lock (rwlock).

To recap, the invariant is: Either multiple readers or a single writer.

This is not designed for direct use but as a building block for locks.

Thus, it is not reentrant and it may misbehave if used incorrectly (i.e. you can release even if you’re not even holding it). It’s also not fair and it is designed to always prefer writers over readers.

The lock is heavily optimized for uncontended scenarios but performance should be close to ideal in any case except for when multiple writers are competing with each other.

The only drawback of the implementation is that it only supports a maximum of 511 simultaneous readers, queued readers and writers each. Anything beyond that overflows, causing all operations on the lock (starting from and including the one that overflowed it) to panic. This means that the rwlock invariant can never be compromised this way.

Trait Implementations§

Source§

impl Debug for RwFutex2

Source§

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

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

impl Default for RwFutex2

Source§

fn default() -> RwFutex2

Creates a new instance.

Source§

impl RwLock for RwFutex2

Source§

fn acquire_read(&self)

Acquires a read lock.

This blocks until the lock is ours.

Source§

fn acquire_write(&self)

Acquries a write lock.

This blocks until the lock is ours.

Source§

fn release_read(&self, _: ())

Releases a read lock.

Source§

fn release_write(&self, _: ())

Releases a write lock.

Source§

type ReadLockState = ()

Source§

type WriteLockState = ()

Auto Trait Implementations§

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.