projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refuse recursive read locks in lockorder testing
[rust-lightning]
/
lightning
/
src
/
sync
/
nostd_sync.rs
diff --git
a/lightning/src/sync/nostd_sync.rs
b/lightning/src/sync/nostd_sync.rs
index caf88a7cc04a8617a86e63988a7cc7a291fe96bc..e17aa6ab15faa5dc33b66dbc1b80ab79fd36cb18 100644
(file)
--- a/
lightning/src/sync/nostd_sync.rs
+++ b/
lightning/src/sync/nostd_sync.rs
@@
-2,6
+2,7
@@
pub use ::alloc::sync::Arc;
use core::ops::{Deref, DerefMut};
use core::time::Duration;
use core::cell::{RefCell, Ref, RefMut};
use core::ops::{Deref, DerefMut};
use core::time::Duration;
use core::cell::{RefCell, Ref, RefMut};
+use super::{LockTestExt, LockHeldState};
pub type LockResult<Guard> = Result<Guard, ()>;
pub type LockResult<Guard> = Result<Guard, ()>;
@@
-61,6
+62,14
@@
impl<T> Mutex<T> {
}
}
}
}
+impl<T> LockTestExt for Mutex<T> {
+ #[inline]
+ fn held_by_thread(&self) -> LockHeldState {
+ if self.lock().is_err() { return LockHeldState::HeldByThread; }
+ else { return LockHeldState::NotHeldByThread; }
+ }
+}
+
pub struct RwLock<T: ?Sized> {
inner: RefCell<T>
}
pub struct RwLock<T: ?Sized> {
inner: RefCell<T>
}
@@
-116,4
+125,12
@@
impl<T> RwLock<T> {
}
}
}
}
+impl<T> LockTestExt for RwLock<T> {
+ #[inline]
+ fn held_by_thread(&self) -> LockHeldState {
+ if self.write().is_err() { return LockHeldState::HeldByThread; }
+ else { return LockHeldState::NotHeldByThread; }
+ }
+}
+
pub type FairRwLock<T> = RwLock<T>;
pub type FairRwLock<T> = RwLock<T>;