Skip to content

Commit 4dbdb6f

Browse files
theunijanus
authored andcommitted
tests: get rid of remaining manual critsect usage
1 parent 741e486 commit 4dbdb6f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/test/sync_tests.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
3737
template <typename MutexType>
3838
void TestDoubleLock2(MutexType& m)
3939
{
40-
ENTER_CRITICAL_SECTION(m);
41-
LEAVE_CRITICAL_SECTION(m);
40+
LOCK(m);
4241
}
4342

4443
template <typename MutexType>
@@ -48,31 +47,31 @@ void TestDoubleLock(bool should_throw)
4847
g_debug_lockorder_abort = false;
4948

5049
MutexType m;
51-
ENTER_CRITICAL_SECTION(m);
52-
if (should_throw) {
53-
BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
50+
{
51+
LOCK(m);
52+
if (should_throw) {
53+
BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
5454
HasReason("double lock detected"));
55-
} else {
56-
BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
55+
} else {
56+
BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
57+
}
5758
}
58-
LEAVE_CRITICAL_SECTION(m);
59-
6059
BOOST_CHECK(LockStackEmpty());
6160

6261
g_debug_lockorder_abort = prev;
6362
}
6463
#endif /* DEBUG_LOCKORDER */
6564

6665
template <typename MutexType>
67-
void TestInconsistentLockOrderDetected(MutexType& mutex1, MutexType& mutex2) NO_THREAD_SAFETY_ANALYSIS
66+
void TestInconsistentLockOrderDetected(MutexType& mutex1, MutexType& mutex2)
6867
{
69-
ENTER_CRITICAL_SECTION(mutex1);
70-
ENTER_CRITICAL_SECTION(mutex2);
68+
{
69+
WAIT_LOCK(mutex1, lock1);
70+
LOCK(mutex2);
7171
#ifdef DEBUG_LOCKORDER
72-
BOOST_CHECK_EXCEPTION(LEAVE_CRITICAL_SECTION(mutex1), std::logic_error, HasReason("mutex1 was not most recent critical section locked"));
72+
BOOST_CHECK_EXCEPTION(REVERSE_LOCK(lock1, mutex1), std::logic_error, HasReason("mutex1 was not most recent critical section locked"));
7373
#endif // DEBUG_LOCKORDER
74-
LEAVE_CRITICAL_SECTION(mutex2);
75-
LEAVE_CRITICAL_SECTION(mutex1);
74+
}
7675
BOOST_CHECK(LockStackEmpty());
7776
}
7877
} // namespace

0 commit comments

Comments
 (0)