Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal/catch_message_info.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-08-23 00:15:53 +0200
committerMartin Hořeňovský2025-08-23 11:08:18 +0200
commit582200a1f8ddd6f435d1264668c7074121c2636c (patch)
tree06629812ca77ebbd77a35424162e197bb979d85e /src/catch2/internal/catch_message_info.cpp
parentf4e05a67bb5a57ee6e051fc8c391b32cbf927f7d (diff)
downloadcatch3-582200a1f8ddd6f435d1264668c7074121c2636c.tar.gz
Make message macros (FAIL, WARN, INFO, etc) thread safe
This builds on the existing work to make assertion thread safe, by adding an extra synchronization point in the holder of `ReusableStringStream`'s stream instances, as those are used to build the messages, and finishing the move of message scope holders to be thread-local.
Diffstat (limited to 'src/catch2/internal/catch_message_info.cpp')
-rw-r--r--src/catch2/internal/catch_message_info.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/catch2/internal/catch_message_info.cpp b/src/catch2/internal/catch_message_info.cpp
index e0e9dc7e..bc887abf 100644
--- a/src/catch2/internal/catch_message_info.cpp
+++ b/src/catch2/internal/catch_message_info.cpp
@@ -10,16 +10,17 @@
namespace Catch {
- MessageInfo::MessageInfo( StringRef _macroName,
- SourceLineInfo const& _lineInfo,
- ResultWas::OfType _type )
+ MessageInfo::MessageInfo( StringRef _macroName,
+ SourceLineInfo const& _lineInfo,
+ ResultWas::OfType _type )
: macroName( _macroName ),
lineInfo( _lineInfo ),
type( _type ),
sequence( ++globalCount )
{}
- // This may need protecting if threading support is added
- unsigned int MessageInfo::globalCount = 0;
+ // Messages are owned by their individual threads, so the counter should be thread-local as well.
+ // Alternative consideration: atomic, so threads don't share IDs and things are easier to debug.
+ thread_local unsigned int MessageInfo::globalCount = 0;
} // end namespace Catch