Skip to content

Commit 7a7939b

Browse files
committed
fix: Fixed racing-condition when switching to another TTY _and_ disconnecting
the audio device at the same time
1 parent e610a8e commit 7a7939b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/utils/Log.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ void Log::write(const QString& msg, bool force, bool useStdErr, LoggingMode mode
120120
if(mode == LM_UNSPECIFIED)
121121
mode = loggingMode;
122122

123+
mutex.lock();
124+
123125
QFile file(path());
124126
if (mode == LM_ALL || mode == LM_FILE)
125127
{
@@ -136,6 +138,8 @@ void Log::write(const QString& msg, bool force, bool useStdErr, LoggingMode mode
136138
(useStdErr ? err : out) << msg.toUtf8().constData() << Qt::endl;
137139
(useStdErr ? err : out).flush();
138140
}
141+
142+
mutex.unlock();
139143
}
140144

141145
QString Log::prepareDebugMessage(const QString& message, util::source_location location)

src/utils/Log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string>
1919
#include <QString>
2020
#include <QTextStream>
21+
#include <QMutex>
2122

2223
// TODO Move Utils.h out of AudioDrivers/Base into a common subproject
2324
#include "Utils.h"
@@ -101,6 +102,7 @@ class Log
101102
LoggingMode loggingMode = LM_ALL;
102103
bool useSimpleFormat = false;
103104
Severity minSeverity = Debug;
105+
QMutex mutex = QMutex();
104106
};
105107

106108
#endif // LOG_H

0 commit comments

Comments
 (0)