tests: get rid of remaining manual critsect usage
What changed, and why it matters
This is a test-only cleanup change. It replaces old-style manual lock/unlock macros with safer automatic lock helpers in a single test file. There is no change to the actual Bitcoin Core software that users run, and no security bug is being fixed.
No action needed. This is a routine test-code refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies src/test/sync_tests.cpp to remove remaining ENTER_CRITICAL_SECTION/LEAVE_CRITICAL_SECTION usage in favor of RAII-style LOCK, WAIT_LOCK, and REVERSE_LOCK helpers. This is a refactoring of synchronization test code under DEBUG_LOCKORDER. No production code is changed, and no vulnerability is patched.
Changed components
src/test/sync_tests.cppInspect captured patch +14 / −15
diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp
index 0576bf16..dcd1b1ce 100644
--- a/src/test/sync_tests.cpp
+++ b/src/test/sync_tests.cpp
@@ -37,8 +37,7 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
template <typename MutexType>
void TestDoubleLock2(MutexType& m)
{
- ENTER_CRITICAL_SECTION(m);
- LEAVE_CRITICAL_SECTION(m);
+ LOCK(m);
}
template <typename MutexType>
@@ -48,15 +47,15 @@ void TestDoubleLock(bool should_throw)
g_debug_lockorder_abort = false;
MutexType m;
- ENTER_CRITICAL_SECTION(m);
- if (should_throw) {
- BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
+ {
+ LOCK(m);
+ if (should_throw) {
+ BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
HasReason("double lock detected"));
- } else {
- BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
+ } else {
+ BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
+ }
}
- LEAVE_CRITICAL_SECTION(m);
-
BOOST_CHECK(LockStackEmpty());
g_debug_lockorder_abort = prev;
@@ -64,15 +63,15 @@ void TestDoubleLock(bool should_throw)
#endif /* DEBUG_LOCKORDER */
template <typename MutexType>
-void TestInconsistentLockOrderDetected(MutexType& mutex1, MutexType& mutex2) NO_THREAD_SAFETY_ANALYSIS
+void TestInconsistentLockOrderDetected(MutexType& mutex1, MutexType& mutex2)
{
- ENTER_CRITICAL_SECTION(mutex1);
- ENTER_CRITICAL_SECTION(mutex2);
+ {
+ WAIT_LOCK(mutex1, lock1);
+ LOCK(mutex2);
#ifdef DEBUG_LOCKORDER
- BOOST_CHECK_EXCEPTION(LEAVE_CRITICAL_SECTION(mutex1), std::logic_error, HasReason("mutex1 was not most recent critical section locked"));
+ BOOST_CHECK_EXCEPTION(REVERSE_LOCK(lock1, mutex1), std::logic_error, HasReason("mutex1 was not most recent critical section locked"));
#endif // DEBUG_LOCKORDER
- LEAVE_CRITICAL_SECTION(mutex2);
- LEAVE_CRITICAL_SECTION(mutex1);
+ }
BOOST_CHECK(LockStackEmpty());
}
} // namespace
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.