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 RwLock for RwFutex2
impl RwLock for RwFutex2
Source§fn acquire_read(&self)
fn acquire_read(&self)
Acquires a read lock.
This blocks until the lock is ours.
Source§fn acquire_write(&self)
fn acquire_write(&self)
Acquries a write lock.
This blocks until the lock is ours.
Source§fn release_read(&self, _: ())
fn release_read(&self, _: ())
Releases a read lock.
Source§fn release_write(&self, _: ())
fn release_write(&self, _: ())
Releases a write lock.