Skip to main content

RawRwLockUpgrade

Trait RawRwLockUpgrade 

Source
pub unsafe trait RawRwLockUpgrade: RawRwLock {
    type UpgradableGuard;

    // Required methods
    fn lock_upgradable(&self) -> Self::UpgradableGuard;
    fn try_lock_upgradable(&self) -> Option<Self::UpgradableGuard>;
    unsafe fn unlock_upgradable(&self, guard: Self::UpgradableGuard);
    unsafe fn upgrade(
        &self,
        guard: Self::UpgradableGuard,
    ) -> Self::ExclusiveGuard;
    unsafe fn try_upgrade(
        &self,
        guard: Self::UpgradableGuard,
    ) -> Result<Self::ExclusiveGuard, Self::UpgradableGuard>;
}
Expand description

Additional methods for RwLocks which support atomically upgrading a shared lock to an exclusive lock.

This requires acquiring a special “upgradable read lock” instead of a normal shared lock. There may only be one upgradable lock at any time, otherwise deadlocks could occur when upgrading.

§Safety

Implementations must uphold the safety requirements of RawRwLock for the additional methods provided by this trait. A successful upgrade to exclusive access must acquire from the shared-lock releases it replaces.

Required Associated Types§

Source

type UpgradableGuard

Per-acquisition state for an upgradable read lock.

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

Required Methods§

Source

fn lock_upgradable(&self) -> Self::UpgradableGuard

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

Source

fn try_lock_upgradable(&self) -> Option<Self::UpgradableGuard>

Attempts to acquire an upgradable lock without blocking.

Source

unsafe fn unlock_upgradable(&self, guard: Self::UpgradableGuard)

Releases an upgradable lock.

§Safety

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

Source

unsafe fn upgrade(&self, guard: Self::UpgradableGuard) -> Self::ExclusiveGuard

Upgrades an upgradable lock to an exclusive lock.

§Safety

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

Source

unsafe fn try_upgrade( &self, guard: Self::UpgradableGuard, ) -> Result<Self::ExclusiveGuard, Self::UpgradableGuard>

Attempts to upgrade an upgradable lock to an exclusive lock without blocking.

On success, returns Ok with the exclusive state. On failure, the upgradable lock remains held and its state is returned in Err.

§Safety

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

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§