Skip to content

Commit 7aa6a9d

Browse files
committed
WIP: Check perf with dummy mutex/lock
1 parent a699f1f commit 7aa6a9d

6 files changed

Lines changed: 26 additions & 23 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ set(IMPL_HEADERS
139139
${SOURCES_DIR}/internal/catch_test_registry.hpp
140140
${SOURCES_DIR}/internal/catch_test_spec_parser.hpp
141141
${SOURCES_DIR}/internal/catch_textflow.hpp
142+
${SOURCES_DIR}/internal/catch_thread_support.hpp
142143
${SOURCES_DIR}/internal/catch_to_string.hpp
143144
${SOURCES_DIR}/internal/catch_uncaught_exceptions.hpp
144145
${SOURCES_DIR}/internal/catch_uniform_floating_point_distribution.hpp

src/catch2/catch_all.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
#include <catch2/internal/catch_test_registry.hpp>
122122
#include <catch2/internal/catch_test_spec_parser.hpp>
123123
#include <catch2/internal/catch_textflow.hpp>
124+
#include <catch2/internal/catch_thread_support.hpp>
124125
#include <catch2/internal/catch_to_string.hpp>
125126
#include <catch2/internal/catch_uncaught_exceptions.hpp>
126127
#include <catch2/internal/catch_uniform_floating_point_distribution.hpp>

src/catch2/internal/catch_run_context.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ namespace Catch {
312312
}
313313

314314
// From here, we are touching shared state and need mutex.
315-
std::lock_guard<std::mutex> lock( m_assertionMutex );
315+
Detail::LockGuard lock( m_assertionMutex );
316316
{
317317
if ( Detail::g_clearMessageScopes ) {
318318
m_messageScopes.clear();
@@ -334,7 +334,7 @@ namespace Catch {
334334

335335
void RunContext::notifyAssertionStarted( AssertionInfo const& info ) {
336336
if (m_reportAssertionStarting) {
337-
std::lock_guard<std::mutex> lock( m_assertionMutex );
337+
Detail::LockGuard lock( m_assertionMutex );
338338
auto _ = scopedDeactivate( *m_outputRedirect );
339339
m_reporter->assertionStarting( info );
340340
}
@@ -492,7 +492,7 @@ namespace Catch {
492492
// m_lastResult is updated inside the assertion slow-path, so it needs to be mutexed as well
493493
// TODO: m_lastResult is not updated in the fast path, is there a point in support it at all?
494494
// TODO: also shouldn't it be a thread-local, since assertions are thread-owned until reporter?
495-
std::lock_guard<std::mutex> _( m_assertionMutex );
495+
Detail::LockGuard _( m_assertionMutex );
496496
return &(*m_lastResult);
497497
}
498498

@@ -509,7 +509,7 @@ namespace Catch {
509509
// the fake assertion and stuff.
510510
// TODO: Should we unlock? Trying to let other threads run while fatal error
511511
// is happening is... ill-advised.
512-
std::lock_guard<std::mutex> lock( m_assertionMutex );
512+
Detail::LockGuard lock( m_assertionMutex );
513513
// TODO: scoped deactivate here? Just give up and do best effort?
514514
// the deactivation can break things further, OTOH so can the
515515
// capture
@@ -530,7 +530,7 @@ namespace Catch {
530530

531531

532532
// TODO: Should we keep granular locks here, or take a single lock at the start?
533-
std::lock_guard<std::mutex> lock( m_assertionMutex );
533+
Detail::LockGuard lock( m_assertionMutex );
534534
// Best effort cleanup for sections that have not been destructed yet
535535
// Since this is a fatal error, we have not had and won't have the opportunity to destruct them properly
536536
while (!m_activeSections.empty()) {

src/catch2/internal/catch_run_context.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include <catch2/catch_assertion_result.hpp>
2121
#include <catch2/internal/catch_optional.hpp>
2222
#include <catch2/internal/catch_move_and_forward.hpp>
23+
#include <catch2/internal/catch_thread_support.hpp>
2324

2425
#include <atomic>
25-
#include <mutex>
2626
#include <string>
2727

2828
namespace Catch {
@@ -153,7 +153,7 @@ namespace Catch {
153153

154154
void handleUnfinishedSections();
155155
// TODO: Make this a recursive mutex if we use a single big mutex in the fatal error handler
156-
mutable std::mutex m_assertionMutex;
156+
mutable Detail::Mutex m_assertionMutex;
157157
TestRunInfo m_runInfo;
158158
TestCaseHandle const* m_activeTestCase = nullptr;
159159
ITracker* m_testCaseTracker = nullptr;

src/catch2/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ internal_headers = [
147147
'internal/catch_test_registry.hpp',
148148
'internal/catch_test_spec_parser.hpp',
149149
'internal/catch_textflow.hpp',
150+
'internal/catch_thread_support.hpp',
150151
'internal/catch_to_string.hpp',
151152
'internal/catch_uncaught_exceptions.hpp',
152153
'internal/catch_uniform_floating_point_distribution.hpp',

tests/SelfTest/UsageTests/Misc.tests.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -563,19 +563,19 @@ TEST_CASE("Validate SEH behavior - no crash for stack unwinding", "[approvals][!
563563

564564
#endif // _MSC_VER
565565

566-
#include <thread>
567-
568-
TEST_CASE( "threads" ) {
569-
std::vector<std::thread> threads;
570-
for ( size_t t = 0; t < 16; ++t) {
571-
threads.emplace_back( []() {
572-
for (size_t i = 0; i < 10'000; ++i) {
573-
CHECK( false );
574-
}
575-
} );
576-
}
577-
578-
for (auto& t : threads) {
579-
t.join();
580-
}
581-
}
566+
//#include <thread>
567+
//
568+
//TEST_CASE( "threads" ) {
569+
// std::vector<std::thread> threads;
570+
// for ( size_t t = 0; t < 16; ++t) {
571+
// threads.emplace_back( []() {
572+
// for (size_t i = 0; i < 10'000; ++i) {
573+
// CHECK( false );
574+
// }
575+
// } );
576+
// }
577+
//
578+
// for (auto& t : threads) {
579+
// t.join();
580+
// }
581+
//}

0 commit comments

Comments
 (0)