From b7238399ea4f1ca51d8f7b8f9220af3da0913edf Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Mon, 29 Apr 2019 22:08:59 +0200 Subject: New upstream version 2.1.0~rc5+repack --- TraceFile.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'TraceFile.cpp') diff --git a/TraceFile.cpp b/TraceFile.cpp index 2329b425..87d4a82b 100644 --- a/TraceFile.cpp +++ b/TraceFile.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -28,10 +30,11 @@ private: QTextStream * original_stream_; QtMessageHandler original_handler_; static QTextStream * current_stream_; + static QMutex mutex_; }; QTextStream * TraceFile::impl::current_stream_; - +QMutex TraceFile::impl::mutex_; // delegate to implementation class TraceFile::TraceFile (QString const& trace_file_path) @@ -73,7 +76,10 @@ TraceFile::impl::~impl () void TraceFile::impl::message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg) { Q_ASSERT_X (current_stream_, "TraceFile:message_handler", "no stream to write to"); - *current_stream_ << qFormatLogMessage (type, context, msg) << endl; + { + QMutexLocker lock {&mutex_}; // thread safety - serialize writes to the trace file + *current_stream_ << qFormatLogMessage (type, context, msg) << endl; + } if (QtFatalMsg == type) { -- cgit v1.2.3