mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Merge bitcoin/bitcoin#25109: Strengthen AssertLockNotHeld assertions
436ce0233csync.h: strengthen AssertLockNotHeld assertion (Anthony Towns)7d73f58e9cIncrease threadsafety annotation coverage (Anthony Towns) Pull request description: This changes `AssertLockNotHeld` so that it is annotated with the negative capability for the mutex it refers to. clang applies negative capabilities recursively, so this helps avoid forgetting to annotate functions. Note that this can't reasonably be used for globals, because clang would require every function to be annotated with `EXCLUSIVE_LOCKS_REQUIRED(!g_mutex)` for each global mutex. At present, the only global mutexes that use `AssertLockNotHeld` are `RecursiveMutex` so we treat that as an exception in order to avoid having to add an excessive number of negative annotations. ACKs for top commit: vasild: ACK436ce0233cMarcoFalke: review ACK436ce0233c🌺 Tree-SHA512: 5f16d098790a36b5277324d5ee89cdc87033c19b11c7943c2f630a41c2e3998eb39d356a763e857f4d8fefb6c0c02291f720bb6769bcbdf5e2cd765bf266ab8c
This commit is contained in:
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
explicit MainSignalsImpl(CScheduler& scheduler LIFETIMEBOUND) : m_schedulerClient(scheduler) {}
|
||||
|
||||
void Register(std::shared_ptr<CValidationInterface> callbacks)
|
||||
void Register(std::shared_ptr<CValidationInterface> callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||
{
|
||||
LOCK(m_mutex);
|
||||
auto inserted = m_map.emplace(callbacks.get(), m_list.end());
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
inserted.first->second->callbacks = std::move(callbacks);
|
||||
}
|
||||
|
||||
void Unregister(CValidationInterface* callbacks)
|
||||
void Unregister(CValidationInterface* callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||
{
|
||||
LOCK(m_mutex);
|
||||
auto it = m_map.find(callbacks);
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
//! map entry. After this call, the list may still contain callbacks that
|
||||
//! are currently executing, but it will be cleared when they are done
|
||||
//! executing.
|
||||
void Clear()
|
||||
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||
{
|
||||
LOCK(m_mutex);
|
||||
for (const auto& entry : m_map) {
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
m_map.clear();
|
||||
}
|
||||
|
||||
template<typename F> void Iterate(F&& f)
|
||||
template<typename F> void Iterate(F&& f) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||
{
|
||||
WAIT_LOCK(m_mutex, lock);
|
||||
for (auto it = m_list.begin(); it != m_list.end();) {
|
||||
|
||||
Reference in New Issue
Block a user