wgpu_core/lock/
vanilla.rs1use core::{fmt, ops};
7
8use crate::lock::rank::LockRank;
9
10pub struct RankData;
11
12pub struct Mutex<T>(parking_lot::Mutex<T>);
23
24pub struct MutexGuard<'a, T>(parking_lot::MutexGuard<'a, T>);
28
29impl<T> Mutex<T> {
30 pub fn new(_rank: LockRank, value: T) -> Mutex<T> {
31 Mutex(parking_lot::Mutex::new(value))
32 }
33
34 pub fn lock(&self) -> MutexGuard<'_, T> {
35 MutexGuard(self.0.lock())
36 }
37
38 pub fn get_mut(&mut self) -> &mut T {
39 self.0.get_mut()
40 }
41
42 pub fn into_inner(self) -> T {
43 self.0.into_inner()
44 }
45}
46
47impl<'a, T> ops::Deref for MutexGuard<'a, T> {
48 type Target = T;
49
50 fn deref(&self) -> &Self::Target {
51 self.0.deref()
52 }
53}
54
55impl<'a, T> ops::DerefMut for MutexGuard<'a, T> {
56 fn deref_mut(&mut self) -> &mut Self::Target {
57 self.0.deref_mut()
58 }
59}
60
61impl<T: fmt::Debug> fmt::Debug for Mutex<T> {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 self.0.fmt(f)
64 }
65}
66
67pub struct RwLock<T>(parking_lot::RwLock<T>);
78
79pub struct RwLockReadGuard<'a, T>(parking_lot::RwLockReadGuard<'a, T>);
83
84pub struct RwLockWriteGuard<'a, T>(parking_lot::RwLockWriteGuard<'a, T>);
88
89impl<T> RwLock<T> {
90 pub fn new(_rank: LockRank, value: T) -> RwLock<T> {
91 RwLock(parking_lot::RwLock::new(value))
92 }
93
94 pub fn read(&self) -> RwLockReadGuard<'_, T> {
95 RwLockReadGuard(self.0.read())
96 }
97
98 pub fn write(&self) -> RwLockWriteGuard<'_, T> {
99 RwLockWriteGuard(self.0.write())
100 }
101
102 pub unsafe fn force_unlock_read(&self, _data: RankData) {
107 unsafe { self.0.force_unlock_read() };
108 }
109}
110
111impl<'a, T> RwLockReadGuard<'a, T> {
112 pub fn forget(this: Self) -> RankData {
117 core::mem::forget(this.0);
118
119 RankData
120 }
121}
122
123impl<T: fmt::Debug> fmt::Debug for RwLock<T> {
124 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
125 self.0.fmt(f)
126 }
127}
128
129impl<'a, T> ops::Deref for RwLockReadGuard<'a, T> {
130 type Target = T;
131
132 fn deref(&self) -> &Self::Target {
133 self.0.deref()
134 }
135}
136
137impl<'a, T> ops::Deref for RwLockWriteGuard<'a, T> {
138 type Target = T;
139
140 fn deref(&self) -> &Self::Target {
141 self.0.deref()
142 }
143}
144
145impl<'a, T> ops::DerefMut for RwLockWriteGuard<'a, T> {
146 fn deref_mut(&mut self) -> &mut Self::Target {
147 self.0.deref_mut()
148 }
149}