diff options
| author | Martin Hořeňovský | 2025-08-23 00:15:53 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2025-08-23 11:08:18 +0200 |
| commit | 582200a1f8ddd6f435d1264668c7074121c2636c (patch) | |
| tree | 06629812ca77ebbd77a35424162e197bb979d85e /src/catch2/internal/catch_message_info.cpp | |
| parent | f4e05a67bb5a57ee6e051fc8c391b32cbf927f7d (diff) | |
| download | catch3-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.cpp | 11 |
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 |