Test if a given mutex is locked by the current thread in tests
authorMatt Corallo <git@bluematt.me>
Tue, 7 Feb 2023 19:46:08 +0000 (19:46 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 16 Feb 2023 21:35:23 +0000 (21:35 +0000)
commit6090d9e6a862a2010eb80be56b7449947bc08374
tree4a0063429e5e485ea72370d4dd6d4bb22bf9d532
parent9422370dd2b2ec73115b5950fa5e19db51c8ea73
Test if a given mutex is locked by the current thread in tests

In anticipation of the next commit(s) adding threaded tests, we
need to ensure our lockorder checks work fine with multiple
threads. Sadly, currently we have tests in the form
`assert!(mutex.try_lock().is_ok())` to assert that a given mutex is
not locked by the caller to a function.

The fix is rather simple given we already track mutexes locked by a
thread in our `debug_sync` logic - simply replace the check with a
new extension trait which (for test builds) checks the locked state
by only looking at what was locked by the current thread.
lightning/src/ln/channelmanager.rs
lightning/src/sync/debug_sync.rs
lightning/src/sync/fairrwlock.rs
lightning/src/sync/mod.rs
lightning/src/sync/nostd_sync.rs
lightning/src/sync/test_lockorder_checks.rs