mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user