wgpu_core/lock/
vanilla.rs1use core::{fmt, ops};
7
8pub struct Mutex<T>(parking_lot::Mutex<T>);
19
20pub struct MutexGuard<'a, T>(parking_lot::MutexGuard<'a, T>);
24
25impl<T> Mutex<T> {
26 pub fn new(_rank: super::rank::LockRank, value: T) -> Mutex<T> {
27 Mutex(parking_lot::Mutex::new(value))
28 }
29
30 pub fn lock(&self) -> MutexGuard<T> {
31 MutexGuard(self.0.lock())
32 }
33
34 pub fn into_inner(self) -> T {
35 self.0.into_inner()
36 }
37}
38
39impl<'a, T> ops::Deref for MutexGuard<'a, T> {
40 type Target = T;
41
42 fn deref(&self) -> &Self::Target {
43 self.0.deref()
44 }
45}
46
47impl<'a, T> ops::DerefMut for MutexGuard<'a, T> {
48 fn deref_mut(&mut self) -> &mut Self::Target {
49 self.0.deref_mut()
50 }
51}
52
53impl<T: fmt::Debug> fmt::Debug for Mutex<T> {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 self.0.fmt(f)
56 }
57}
58
59pub struct RwLock<T>(parking_lot::RwLock<T>);
70
71pub struct RwLockReadGuard<'a, T>(parking_lot::RwLockReadGuard<'a, T>);
75
76pub struct RwLockWriteGuard<'a, T>(parking_lot::RwLockWriteGuard<'a, T>);
80
81impl<T> RwLock<T> {
82 pub fn new(_rank: super::rank::LockRank, value: T) -> RwLock<T> {
83 RwLock(parking_lot::RwLock::new(value))
84 }
85
86 pub fn read(&self) -> RwLockReadGuard<T> {
87 RwLockReadGuard(self.0.read())
88 }
89
90 pub fn write(&self) -> RwLockWriteGuard<T> {
91 RwLockWriteGuard(self.0.write())
92 }
93}
94
95impl<'a, T> RwLockWriteGuard<'a, T> {
96 pub fn downgrade(this: Self) -> RwLockReadGuard<'a, T> {
97 RwLockReadGuard(parking_lot::RwLockWriteGuard::downgrade(this.0))
98 }
99}
100
101impl<T: fmt::Debug> fmt::Debug for RwLock<T> {
102 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103 self.0.fmt(f)
104 }
105}
106
107impl<'a, T> ops::Deref for RwLockReadGuard<'a, T> {
108 type Target = T;
109
110 fn deref(&self) -> &Self::Target {
111 self.0.deref()
112 }
113}
114
115impl<'a, T> ops::Deref for RwLockWriteGuard<'a, T> {
116 type Target = T;
117
118 fn deref(&self) -> &Self::Target {
119 self.0.deref()
120 }
121}
122
123impl<'a, T> ops::DerefMut for RwLockWriteGuard<'a, T> {
124 fn deref_mut(&mut self) -> &mut Self::Target {
125 self.0.deref_mut()
126 }
127}