Skip to main content

RawRwLockFair

Trait RawRwLockFair 

Source
pub unsafe trait RawRwLockFair: RawRwLock {
    // Required methods
    unsafe fn unlock_shared_fair(&self, guard: Self::SharedGuard);
    unsafe fn unlock_exclusive_fair(&self, guard: Self::ExclusiveGuard);

    // Provided methods
    unsafe fn bump_shared(&self, guard: &mut Self::SharedGuard) { ... }
    unsafe fn bump_exclusive(&self, guard: &mut Self::ExclusiveGuard) { ... }
}
Expand description

Additional methods for RwLocks which support fair unlocking.

Fair unlocking gives waiting threads priority over new attempts to acquire the lock, without giving other threads the opportunity to “steal” it in the meantime. This is typically slower than unfair unlocking, but may be necessary in certain circumstances.

§Safety

Implementations must uphold the safety requirements of RawRwLock for the additional methods provided by this trait.

Required Methods§

Source

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

Releases a shared lock using a fair unlock protocol.

§Safety

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

Source

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

Releases an exclusive lock using a fair unlock protocol.

§Safety

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

Provided Methods§

Source

unsafe fn bump_shared(&self, guard: &mut Self::SharedGuard)

Temporarily yields a shared lock to a waiting thread if there is one.

This method is functionally equivalent to calling unlock_shared_fair followed by lock_shared, however it can be much more efficient in the case where there are no waiting threads.

§Safety

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

Implementations may unwind only with ownership in the original mode and valid guard state restored. If restoration fails, they must abort.

§Aborts

The default implementation aborts if re-locking the RwLock panics.

Source

unsafe fn bump_exclusive(&self, guard: &mut Self::ExclusiveGuard)

Temporarily yields an exclusive lock to a waiting thread if there is one.

This method is functionally equivalent to calling unlock_exclusive_fair followed by lock_exclusive, however it can be much more efficient in the case where there are no waiting threads.

§Safety

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

Implementations may unwind only with ownership in the original mode and valid guard state restored. If restoration fails, they must abort.

§Aborts

The default implementation aborts if re-locking the RwLock panics.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§