Struct std::sync::StaticRwLock
[−]
[src]
pub struct StaticRwLock { // some fields omitted }
Structure representing a statically allocated RwLock.
This structure is intended to be used inside of a static
and will provide
automatic global access as well as lazy initialization. The internal
resources of this RwLock, however, must be manually deallocated.
Examples
#![feature(static_rwlock)] fn main() { use std::sync::{StaticRwLock, RW_LOCK_INIT}; static LOCK: StaticRwLock = RW_LOCK_INIT; { let _g = LOCK.read().unwrap(); // ... shared read access } { let _g = LOCK.write().unwrap(); // ... exclusive write access } unsafe { LOCK.destroy() } // free all resources }#![feature(static_rwlock)] use std::sync::{StaticRwLock, RW_LOCK_INIT}; static LOCK: StaticRwLock = RW_LOCK_INIT; { let _g = LOCK.read().unwrap(); // ... shared read access } { let _g = LOCK.write().unwrap(); // ... exclusive write access } unsafe { LOCK.destroy() } // free all resources
Methods
impl StaticRwLock
const fn new() -> StaticRwLock
Creates a new rwlock.
fn read(&'static self) -> LockResult<RwLockReadGuard<'static, ()>>
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
See RwLock::read
.
fn try_read(&'static self) -> TryLockResult<RwLockReadGuard<'static, ()>>
Attempts to acquire this lock with shared read access.
See RwLock::try_read
.
fn write(&'static self) -> LockResult<RwLockWriteGuard<'static, ()>>
Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.
See RwLock::write
.
fn try_write(&'static self) -> TryLockResult<RwLockWriteGuard<'static, ()>>
Attempts to lock this rwlock with exclusive write access.
See RwLock::try_write
.
unsafe fn destroy(&'static self)
Deallocates all resources associated with this static lock.
This method is unsafe to call as there is no guarantee that there are no active users of the lock, and this also doesn't prevent any future users of this lock. This method is required to be called to not leak memory on all platforms.