mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-26 14:59:16 +02:00
Merge #11640: Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection
9c4dc597ddUse LOCK macros for non-recursive locks (Russell Yanofsky)1382913e61Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection (Russell Yanofsky)ba1f095aadMOVEONLY Move AnnotatedMixin declaration (Russell Yanofsky)41b88e9337Add 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:
52
src/test/sync_tests.cpp
Normal file
52
src/test/sync_tests.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2012-2017 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <sync.h>
|
||||
#include <test/test_bitcoin.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
template <typename MutexType>
|
||||
void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
|
||||
{
|
||||
{
|
||||
LOCK2(mutex1, mutex2);
|
||||
}
|
||||
bool error_thrown = false;
|
||||
try {
|
||||
LOCK2(mutex2, mutex1);
|
||||
} catch (const std::logic_error& e) {
|
||||
BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected");
|
||||
error_thrown = true;
|
||||
}
|
||||
#ifdef DEBUG_LOCKORDER
|
||||
BOOST_CHECK(error_thrown);
|
||||
#else
|
||||
BOOST_CHECK(!error_thrown);
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(sync_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
|
||||
{
|
||||
#ifdef DEBUG_LOCKORDER
|
||||
bool prev = g_debug_lockorder_abort;
|
||||
g_debug_lockorder_abort = false;
|
||||
#endif
|
||||
|
||||
CCriticalSection rmutex1, rmutex2;
|
||||
TestPotentialDeadLockDetected(rmutex1, rmutex2);
|
||||
|
||||
CWaitableCriticalSection mutex1, mutex2;
|
||||
TestPotentialDeadLockDetected(mutex1, mutex2);
|
||||
|
||||
#ifdef DEBUG_LOCKORDER
|
||||
g_debug_lockorder_abort = prev;
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user