mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-10 19:43:13 +02:00
Merge #11640: Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection
9c4dc597dd
Use LOCK macros for non-recursive locks (Russell Yanofsky)1382913e61
Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection (Russell Yanofsky)ba1f095aad
MOVEONLY Move AnnotatedMixin declaration (Russell Yanofsky)41b88e9337
Add unit test for DEBUG_LOCKORDER code (Russell Yanofsky) Pull request description: Make LOCK macros work with non-recursive mutexes, and use wherever possible for better deadlock detection. Also add unit test for DEBUG_LOCKORDER code. Tree-SHA512: 64ef209307f28ecd0813a283f15c6406138c6ffe7f6cbbd084161044db60e2c099a7d0d2edcd1c5e7770a115e9b931b486e86c9a777bdc96d2e8a9f4dc192942
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <threadinterrupt.h>
|
||||
|
||||
#include <sync.h>
|
||||
|
||||
CThreadInterrupt::CThreadInterrupt() : flag(false) {}
|
||||
|
||||
CThreadInterrupt::operator bool() const
|
||||
@@ -20,7 +22,7 @@ void CThreadInterrupt::reset()
|
||||
void CThreadInterrupt::operator()()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mut);
|
||||
LOCK(mut);
|
||||
flag.store(true, std::memory_order_release);
|
||||
}
|
||||
cond.notify_all();
|
||||
@@ -28,7 +30,7 @@ void CThreadInterrupt::operator()()
|
||||
|
||||
bool CThreadInterrupt::sleep_for(std::chrono::milliseconds rel_time)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mut);
|
||||
WAIT_LOCK(mut, lock);
|
||||
return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user