[−][src]Struct node_replication::rwlock::RwLock
A scalable reader-writer lock.
This lock favours reader performance over writers. Each reader thread gets its own "lock" while writers share a single lock.
T represents the underlying type protected by the lock.
Calling read() returns a read-guard that can be used to safely read T.
Calling write() returns a write-guard that can be used to safely mutate T.
Implementations
impl<T> RwLock<T> where
T: Sized + Default + Sync, [src]
T: Sized + Default + Sync,
pub fn write(&self, n: usize) -> WriteGuard<'_, T>[src]
Locks the underlying data-structure for writes. The caller can retrieve
a mutable reference from the returned WriteGuard.
n is the number of active readers currently using this reader-writer lock.
Example
use node_replication::rwlock::RwLock;
// Create the lock.
let lock = RwLock::<usize>::default();
// Acquire the write lock. This returns a guard that can be used
// to perform writes against the protected data. We need to know
// the number of concurrent reader threads upfront.
const N_CONCURRENT_READERS: usize = 32;
let mut w_guard = lock.write(N_CONCURRENT_READERS);
*w_guard = 777;pub fn read(&self, tid: usize) -> ReadGuard<'_, T>[src]
Locks the underlying data-structure for reads. Allows multiple readers to acquire the lock. Blocks until there aren't any active writers.
Example
use node_replication::rwlock::RwLock;
// Create the lock.
let lock = RwLock::<usize>::default();
// Acquire the read lock. This returns a guard that can be used
// to perform reads against the protected data. We need
// a thread identifier to acquire this lock.
const MY_THREAD_ID: usize = 16;
let r_guard = lock.read(MY_THREAD_ID);
assert_eq!(0, *r_guard);Trait Implementations
impl<T> Default for RwLock<T> where
T: Sized + Default + Sync, [src]
T: Sized + Default + Sync,
fn default() -> RwLock<T>[src]
Returns a new instance of a RwLock. Default constructs the underlying data structure.
impl<T: ?Sized + Default + Sync> Sync for RwLock<T>[src]
Sync trait allows RwLock to be shared between threads. The read() and
write() logic ensures that we will never have threads writing to and
reading from the underlying data structure simultaneously.
Auto Trait Implementations
impl<T> !RefUnwindSafe for RwLock<T>
impl<T> Send for RwLock<T> where
T: Send,
T: Send,
impl<T> Unpin for RwLock<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for RwLock<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,