[core] Implement downgrade for the lock module's RwLocks.

Implement `RwLockWriteGuard::downgrade` for `lock::vanilla` and
`lock::ranked`, to downgrade a write lock to a read lock.
This commit is contained in:
Jim Blandy authored and Erich Gubler committed 2024-05-03 13:06:00 -04:00
1 parent 651214ef74
commit 7c842a3b48
2 files changed
+15

No files matched your search

+9
View File
@@ -281,6 +281,15 @@ impl<T> RwLock<T> {
}
}
impl<'a, T> RwLockWriteGuard<'a, T> {
pub fn downgrade(this: Self) -> RwLockReadGuard<'a, T> {
RwLockReadGuard {
inner: parking_lot::RwLockWriteGuard::downgrade(this.inner),
saved: this.saved,
}
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for RwLock<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
+6
View File
@@ -86,6 +86,12 @@ impl<T> RwLock<T> {
}
}
impl<'a, T> RwLockWriteGuard<'a, T> {
pub fn downgrade(this: Self) -> RwLockReadGuard<'a, T> {
RwLockReadGuard(parking_lot::RwLockWriteGuard::downgrade(this.0))
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for RwLock<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)