Skip to content

Commit eb6eaf5

Browse files
da-xoutfoxxed
authored andcommitted
core/log: add a mutex to protect stdoutStream
QTextStream is not thread safe.
1 parent 7511545 commit eb6eaf5

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

src/core/logging.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <qlist.h>
1515
#include <qlogging.h>
1616
#include <qloggingcategory.h>
17+
#include <qmutex.h>
1718
#include <qnamespace.h>
1819
#include <qobject.h>
1920
#include <qobjectdefs.h>
@@ -220,6 +221,7 @@ void LogManager::messageHandler(
220221
}
221222

222223
if (display) {
224+
auto locker = QMutexLocker(&self->stdoutMutex);
223225
LogMessage::formatMessage(
224226
self->stdoutStream,
225227
message,

src/core/logging.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <qlatin1stringview.h>
1111
#include <qlogging.h>
1212
#include <qloggingcategory.h>
13+
#include <qmutex.h>
1314
#include <qobject.h>
1415
#include <qtmetamacros.h>
1516

@@ -135,6 +136,7 @@ class LogManager: public QObject {
135136
QHash<QLatin1StringView, CategoryFilter> allFilters;
136137

137138
QTextStream stdoutStream;
139+
QMutex stdoutMutex;
138140
LoggingThreadProxy threadProxy;
139141

140142
friend void initLogCategoryLevel(const char* name, QtMsgType defaultLevel);

0 commit comments

Comments
 (0)