Skip to content

Commit 19efaf4

Browse files
committed
f drop unused skip_checks bool
1 parent 225801d commit 19efaf4

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

lightning/src/debug_sync.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ impl std::hash::Hash for MutexMetadata {
6767
pub struct Mutex<T: Sized> {
6868
inner: StdMutex<T>,
6969
deps: Arc<MutexMetadata>,
70-
skip_checks: bool
7170
}
7271

7372
#[must_use = "if unused the Mutex will immediately unlock"]
@@ -119,47 +118,42 @@ impl<T> Mutex<T> {
119118
#[cfg(feature = "backtrace")]
120119
mutex_construction_bt: Backtrace::new(),
121120
}),
122-
skip_checks: false,
123121
}
124122
}
125123

126124
pub fn lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
127-
if !self.skip_checks {
128-
MUTEXES_HELD.with(|held| {
129-
// For each mutex which is currently locked, check that no mutex's locked-before
130-
// set includes the mutex we're about to lock, which would imply a lockorder
131-
// inversion.
132-
for locked in held.borrow().iter() {
133-
for locked_dep in locked.locked_before.lock().unwrap().iter() {
134-
if *locked_dep == self.deps {
135-
#[cfg(feature = "backtrace")]
136-
panic!("Tried to violate existing lockorder.\nMutex that should be locked after the current lock was created at the following backtrace.\nNote that to get a backtrace for the lockorder violation, you should set RUST_BACKTRACE=1\n{:?}", locked.mutex_construction_bt);
137-
#[cfg(not(feature = "backtrace"))]
138-
panic!("Tried to violate existing lockorder. Build with the backtrace feature for more info.");
139-
}
125+
MUTEXES_HELD.with(|held| {
126+
// For each mutex which is currently locked, check that no mutex's locked-before
127+
// set includes the mutex we're about to lock, which would imply a lockorder
128+
// inversion.
129+
for locked in held.borrow().iter() {
130+
for locked_dep in locked.locked_before.lock().unwrap().iter() {
131+
if *locked_dep == self.deps {
132+
#[cfg(feature = "backtrace")]
133+
panic!("Tried to violate existing lockorder.\nMutex that should be locked after the current lock was created at the following backtrace.\nNote that to get a backtrace for the lockorder violation, you should set RUST_BACKTRACE=1\n{:?}", locked.mutex_construction_bt);
134+
#[cfg(not(feature = "backtrace"))]
135+
panic!("Tried to violate existing lockorder. Build with the backtrace feature for more info.");
140136
}
141-
// Insert any already-held mutexes in our locked-before set.
142-
self.deps.locked_before.lock().unwrap().insert(Arc::clone(locked));
143137
}
144-
held.borrow_mut().insert(Arc::clone(&self.deps));
145-
});
146-
}
138+
// Insert any already-held mutexes in our locked-before set.
139+
self.deps.locked_before.lock().unwrap().insert(Arc::clone(locked));
140+
}
141+
held.borrow_mut().insert(Arc::clone(&self.deps));
142+
});
147143
self.inner.lock().map(|lock| MutexGuard { mutex: self, lock }).map_err(|_| ())
148144
}
149145

150146
pub fn try_lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
151147
let res = self.inner.try_lock().map(|lock| MutexGuard { mutex: self, lock }).map_err(|_| ());
152-
if !self.skip_checks && res.is_ok() {
153-
MUTEXES_HELD.with(|held| {
154-
// Since a try-lock will simply fail if the lock is held already, we do not
155-
// consider try-locks to ever generate lockorder inversions. However, if a try-lock
156-
// succeeds, we do consider it to have created lockorder dependencies.
157-
for locked in held.borrow().iter() {
158-
self.deps.locked_before.lock().unwrap().insert(Arc::clone(locked));
159-
}
160-
held.borrow_mut().insert(Arc::clone(&self.deps));
161-
});
162-
}
148+
MUTEXES_HELD.with(|held| {
149+
// Since a try-lock will simply fail if the lock is held already, we do not
150+
// consider try-locks to ever generate lockorder inversions. However, if a try-lock
151+
// succeeds, we do consider it to have created lockorder dependencies.
152+
for locked in held.borrow().iter() {
153+
self.deps.locked_before.lock().unwrap().insert(Arc::clone(locked));
154+
}
155+
held.borrow_mut().insert(Arc::clone(&self.deps));
156+
});
163157
res
164158
}
165159
}

0 commit comments

Comments
 (0)