Skip to content

Commit

Permalink
Make RwLockReadGuard covariant
Browse files Browse the repository at this point in the history
And refactor `RwLock` implementation into
non-generic core and generic interface
  • Loading branch information
Jules-Bertholet committed May 26, 2023
1 parent f738cfd commit c835356
Show file tree
Hide file tree
Showing 2 changed files with 701 additions and 395 deletions.
13 changes: 13 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ impl<T: ?Sized> Mutex<T> {
pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.data.get() }
}

/// Unlocks the mutex directly.
///
/// # Safety
///
/// This function is intended to be used only in the case where the mutex is locked,
/// and the guard is subsequently forgotten. Calling this while you don't hold a lock
/// on the mutex will likely lead to UB.
pub(crate) unsafe fn unlock_unchecked(&self) {
// Remove the last bit and notify a waiting lock operation.
self.state.fetch_sub(1, Ordering::Release);
self.lock_ops.notify(1);
}
}

impl<T: ?Sized> Mutex<T> {
Expand Down
Loading

0 comments on commit c835356

Please sign in to comment.