mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-15 06:12:37 -03:00
190bf62be1
Call sync.h primitives "locks" and "mutexes" instead of "blocks" and "waitable critical sections" to match current coding conventions and c++11 standard names. This PR does not rename the "CCriticalSection" class (though this could be done as a followup) because it is used everywhere and would swamp the other changes in this PR. Plain mutexes should mostly be preferred instead of recursive mutexes in new code anyway. -BEGIN VERIFY SCRIPT- set -x set -e ren() { git grep -l $1 | xargs sed -i s/$1/$2/; } ren CCriticalBlock UniqueLock ren CWaitableCriticalSection Mutex ren CConditionVariable std::condition_variable ren cs_GenesisWait g_genesis_wait_mutex ren condvar_GenesisWait g_genesis_wait_cv perl -0777 -pi -e 's/.*typedef.*condition_variable.*\n\n?//g' src/sync.h -END VERIFY SCRIPT-
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
// 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);
|
|
|
|
Mutex mutex1, mutex2;
|
|
TestPotentialDeadLockDetected(mutex1, mutex2);
|
|
|
|
#ifdef DEBUG_LOCKORDER
|
|
g_debug_lockorder_abort = prev;
|
|
#endif
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|