Skip to content

Commit e0a57b2

Browse files
committed
f lockmetadata
1 parent 8b39f29 commit e0a57b2

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lightning/src/debug_sync.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,30 @@ impl Condvar {
4343
}
4444

4545
thread_local! {
46-
/// We track the set of locks currently held by a reference to their `MutexMetadata`
47-
static LOCKS_HELD: RefCell<HashSet<Arc<MutexMetadata>>> = RefCell::new(HashSet::new());
46+
/// We track the set of locks currently held by a reference to their `LockMetadata`
47+
static LOCKS_HELD: RefCell<HashSet<Arc<LockMetadata>>> = RefCell::new(HashSet::new());
4848
}
4949
static LOCK_IDX: AtomicUsize = AtomicUsize::new(0);
5050

5151
/// Metadata about a single lock, by id, the set of things locked-before it, and the backtrace of
5252
/// when the Mutex itself was constructed.
53-
struct MutexMetadata {
53+
struct LockMetadata {
5454
lock_idx: u64,
55-
locked_before: StdMutex<HashSet<Arc<MutexMetadata>>>,
55+
locked_before: StdMutex<HashSet<Arc<LockMetadata>>>,
5656
#[cfg(feature = "backtrace")]
5757
lock_construction_bt: Backtrace,
5858
}
59-
impl PartialEq for MutexMetadata {
60-
fn eq(&self, o: &MutexMetadata) -> bool { self.lock_idx == o.lock_idx }
59+
impl PartialEq for LockMetadata {
60+
fn eq(&self, o: &LockMetadata) -> bool { self.lock_idx == o.lock_idx }
6161
}
62-
impl Eq for MutexMetadata {}
63-
impl std::hash::Hash for MutexMetadata {
62+
impl Eq for LockMetadata {}
63+
impl std::hash::Hash for LockMetadata {
6464
fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64(self.lock_idx); }
6565
}
6666

67-
impl MutexMetadata {
68-
fn new() -> MutexMetadata {
69-
MutexMetadata {
67+
impl LockMetadata {
68+
fn new() -> LockMetadata {
69+
LockMetadata {
7070
locked_before: StdMutex::new(HashSet::new()),
7171
lock_idx: LOCK_IDX.fetch_add(1, Ordering::Relaxed) as u64,
7272
#[cfg(feature = "backtrace")]
@@ -75,7 +75,7 @@ impl MutexMetadata {
7575
}
7676

7777
// Returns whether we were a recursive lock (only relevant for read)
78-
fn _pre_lock(this: &Arc<MutexMetadata>, read: bool) -> bool {
78+
fn _pre_lock(this: &Arc<LockMetadata>, read: bool) -> bool {
7979
let mut inserted = false;
8080
LOCKS_HELD.with(|held| {
8181
// For each lock which is currently locked, check that no lock's locked-before
@@ -108,10 +108,10 @@ impl MutexMetadata {
108108
inserted
109109
}
110110

111-
fn pre_lock(this: &Arc<MutexMetadata>) { Self::_pre_lock(this, false); }
112-
fn pre_read_lock(this: &Arc<MutexMetadata>) -> bool { Self::_pre_lock(this, true) }
111+
fn pre_lock(this: &Arc<LockMetadata>) { Self::_pre_lock(this, false); }
112+
fn pre_read_lock(this: &Arc<LockMetadata>) -> bool { Self::_pre_lock(this, true) }
113113

114-
fn try_locked(this: &Arc<MutexMetadata>) {
114+
fn try_locked(this: &Arc<LockMetadata>) {
115115
LOCKS_HELD.with(|held| {
116116
// Since a try-lock will simply fail if the lock is held already, we do not
117117
// consider try-locks to ever generate lockorder inversions. However, if a try-lock
@@ -126,7 +126,7 @@ impl MutexMetadata {
126126

127127
pub struct Mutex<T: Sized> {
128128
inner: StdMutex<T>,
129-
deps: Arc<MutexMetadata>,
129+
deps: Arc<LockMetadata>,
130130
}
131131

132132
#[must_use = "if unused the Mutex will immediately unlock"]
@@ -170,26 +170,26 @@ impl<T: Sized> DerefMut for MutexGuard<'_, T> {
170170

171171
impl<T> Mutex<T> {
172172
pub fn new(inner: T) -> Mutex<T> {
173-
Mutex { inner: StdMutex::new(inner), deps: Arc::new(MutexMetadata::new()) }
173+
Mutex { inner: StdMutex::new(inner), deps: Arc::new(LockMetadata::new()) }
174174
}
175175

176176
pub fn lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
177-
MutexMetadata::pre_lock(&self.deps);
177+
LockMetadata::pre_lock(&self.deps);
178178
self.inner.lock().map(|lock| MutexGuard { mutex: self, lock }).map_err(|_| ())
179179
}
180180

181181
pub fn try_lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
182182
let res = self.inner.try_lock().map(|lock| MutexGuard { mutex: self, lock }).map_err(|_| ());
183183
if res.is_ok() {
184-
MutexMetadata::try_locked(&self.deps);
184+
LockMetadata::try_locked(&self.deps);
185185
}
186186
res
187187
}
188188
}
189189

190190
pub struct RwLock<T: Sized> {
191191
inner: StdRwLock<T>,
192-
deps: Arc<MutexMetadata>,
192+
deps: Arc<LockMetadata>,
193193
}
194194

195195
pub struct RwLockReadGuard<'a, T: Sized + 'a> {
@@ -249,23 +249,23 @@ impl<T: Sized> DerefMut for RwLockWriteGuard<'_, T> {
249249

250250
impl<T> RwLock<T> {
251251
pub fn new(inner: T) -> RwLock<T> {
252-
RwLock { inner: StdRwLock::new(inner), deps: Arc::new(MutexMetadata::new()) }
252+
RwLock { inner: StdRwLock::new(inner), deps: Arc::new(LockMetadata::new()) }
253253
}
254254

255255
pub fn read<'a>(&'a self) -> LockResult<RwLockReadGuard<'a, T>> {
256-
let first_lock = MutexMetadata::pre_read_lock(&self.deps);
256+
let first_lock = LockMetadata::pre_read_lock(&self.deps);
257257
self.inner.read().map(|guard| RwLockReadGuard { lock: self, guard, first_lock }).map_err(|_| ())
258258
}
259259

260260
pub fn write<'a>(&'a self) -> LockResult<RwLockWriteGuard<'a, T>> {
261-
MutexMetadata::pre_lock(&self.deps);
261+
LockMetadata::pre_lock(&self.deps);
262262
self.inner.write().map(|guard| RwLockWriteGuard { lock: self, guard }).map_err(|_| ())
263263
}
264264

265265
pub fn try_write<'a>(&'a self) -> LockResult<RwLockWriteGuard<'a, T>> {
266266
let res = self.inner.try_write().map(|guard| RwLockWriteGuard { lock: self, guard }).map_err(|_| ());
267267
if res.is_ok() {
268-
MutexMetadata::try_locked(&self.deps);
268+
LockMetadata::try_locked(&self.deps);
269269
}
270270
res
271271
}

0 commit comments

Comments
 (0)