Struct std::sync::StaticRwLockUnstable [-] [+] [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.

Example

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

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

Attempt to acquire this lock with shared read access.

See RwLock::try_read.

fn write(&'static self) -> LockResult<RwLockWriteGuard<'static, ()>>

Lock 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, ()>>

Attempt to lock this rwlock with exclusive write access.

See RwLock::try_write.

unsafe fn destroy(&'static self)

Deallocate 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.

Trait Implementations

impl Send for StaticRwLock

impl Sync for StaticRwLock