pub unsafe trait RawMutexFair: RawMutex {
// Required method
unsafe fn unlock_fair(&self, guard: Self::Guard);
// Provided method
unsafe fn bump(&self, guard: &mut Self::Guard) { ... }
}Expand description
Additional methods for mutexes which support fair unlocking.
Fair unlocking means that a lock is handed directly over to the next waiting thread if there is one, without giving other threads the opportunity to “steal” the lock 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 RawMutex for
the additional methods provided by this trait.
Required Methods§
Sourceunsafe fn unlock_fair(&self, guard: Self::Guard)
unsafe fn unlock_fair(&self, guard: Self::Guard)
Provided Methods§
Sourceunsafe fn bump(&self, guard: &mut Self::Guard)
unsafe fn bump(&self, guard: &mut Self::Guard)
Temporarily yields the mutex to a waiting thread if there is one.
This method is functionally equivalent to calling unlock_fair followed
by lock, however it can be much more efficient in the case where there
are no waiting threads.
§Safety
This method may only be called if the mutex is held in the current context, see
the documentation of unlock.
Implementations may unwind only with the mutex held and valid guard state restored. If restoration fails, they must abort.
§Aborts
The default implementation aborts if re-locking the mutex panics.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".