Skip to content

Commit d4f3063

Browse files
committed
[core] Fix caller location tracking in lock::ranked.
Properly track the location of callers of `Mutex::lock`, `RwLock::read`, and `RwLock::write`, for use in panic messages.
1 parent 55c9d69 commit d4f3063

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

wgpu-core/src/lock/ranked.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ impl LockState {
113113
/// update the per-thread state accordingly.
114114
///
115115
/// Return the `LockState` that must be restored when this thread is released.
116-
fn acquire(new_rank: LockRank) -> LockState {
116+
fn acquire(new_rank: LockRank, location: &'static Location<'static>) -> LockState {
117117
let state = LOCK_STATE.get();
118-
let location = Location::caller();
119118
// Initially, it's fine to acquire any lock. So we only
120119
// need to check when `last_acquired` is `Some`.
121120
if let Some((ref last_rank, ref last_location)) = state.last_acquired {
@@ -168,7 +167,7 @@ impl<T> Mutex<T> {
168167

169168
#[track_caller]
170169
pub fn lock(&self) -> MutexGuard<T> {
171-
let saved = acquire(self.rank);
170+
let saved = acquire(self.rank, Location::caller());
172171
MutexGuard {
173172
inner: self.inner.lock(),
174173
saved,
@@ -249,16 +248,18 @@ impl<T> RwLock<T> {
249248
}
250249
}
251250

251+
#[track_caller]
252252
pub fn read(&self) -> RwLockReadGuard<T> {
253-
let saved = acquire(self.rank);
253+
let saved = acquire(self.rank, Location::caller());
254254
RwLockReadGuard {
255255
inner: self.inner.read(),
256256
saved,
257257
}
258258
}
259259

260+
#[track_caller]
260261
pub fn write(&self) -> RwLockWriteGuard<T> {
261-
let saved = acquire(self.rank);
262+
let saved = acquire(self.rank, Location::caller());
262263
RwLockWriteGuard {
263264
inner: self.inner.write(),
264265
saved,

0 commit comments

Comments
 (0)