Skip to main content

RawRwLock

Trait RawRwLock 

Source
pub unsafe trait RawRwLock {
    type SharedGuard;
    type ExclusiveGuard;

    const INIT: Self;

    // Required methods
    fn lock_shared(&self) -> Self::SharedGuard;
    fn try_lock_shared(&self) -> Option<Self::SharedGuard>;
    unsafe fn unlock_shared(&self, guard: Self::SharedGuard);
    fn lock_exclusive(&self) -> Self::ExclusiveGuard;
    fn try_lock_exclusive(&self) -> Option<Self::ExclusiveGuard>;
    unsafe fn unlock_exclusive(&self, guard: Self::ExclusiveGuard);
    fn is_locked(&self) -> bool;
    fn is_locked_exclusive(&self) -> bool;
}
Expand description

Basic operations for a reader-writer lock.

Types implementing this trait can be used by RwLock to form a safe and fully-functioning RwLock type.

§Safety

Implementations must allow either shared acquisitions or one exclusive acquisition, with acquire semantics on successful locking and release semantics on unlocking. These requirements also apply to subtraits.

Each successful lock operation returns guard state representing an acquisition in a particular mode. Operations on a held lock must receive the state for that acquisition and mode. Unlocking consumes the state; mode transitions return state for the resulting mode. A transition that returns failure must return valid state for the original acquisition and mode.

Guard state may release its acquisition when dropped, but forgetting it must be safe. A caller with exclusive ownership of the lock object may move or drop it even while it is locked; this must also be safe.

If a lock operation unwinds, it must not leave the caller holding a new acquisition. If an operation consuming guard state unwinds, it must release the acquisition represented by that state, even if it changed modes or re-acquired the lock before panicking. Neither case may release an acquisition held independently of the call.

Required Associated Constants§

Source

const INIT: Self

Initial value for an unlocked RwLock.

Required Associated Types§

Source

type SharedGuard

Per-acquisition state stored in the lock guard.

This type also determines whether guards are Send and Sync. Stateless implementations can use GuardSend or GuardNoSend.

Source

type ExclusiveGuard

Per-acquisition state for an exclusive lock.

This type also determines whether guards are Send and Sync. Stateless implementations can use GuardSend or GuardNoSend.

Required Methods§

Source

fn lock_shared(&self) -> Self::SharedGuard

Acquires a shared lock, blocking the current thread until it is able to do so.

Source

fn try_lock_shared(&self) -> Option<Self::SharedGuard>

Attempts to acquire a shared lock without blocking.

Source

unsafe fn unlock_shared(&self, guard: Self::SharedGuard)

Releases a shared lock.

§Safety

This method requires the state for a shared acquisition of this lock held in the current context.

Source

fn lock_exclusive(&self) -> Self::ExclusiveGuard

Acquires an exclusive lock, blocking the current thread until it is able to do so.

Source

fn try_lock_exclusive(&self) -> Option<Self::ExclusiveGuard>

Attempts to acquire an exclusive lock without blocking.

Source

unsafe fn unlock_exclusive(&self, guard: Self::ExclusiveGuard)

Releases an exclusive lock.

§Safety

This method requires the state for an exclusive acquisition of this lock held in the current context.

Source

fn is_locked(&self) -> bool

Checks if this RwLock is currently locked in any way.

The result is a momentary snapshot and may be stale by the time it is returned.

Source

fn is_locked_exclusive(&self) -> bool

Check if this RwLock is currently exclusively locked.

The result is a momentary snapshot and may be stale by the time it is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§