mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-03-05 15:16:13 -05:00
UI: Add mutex for writing to the log file
fstream is not thread-safe and the act of writing the string and the newline are two separate operations which could execute concurrently in multiple threads, resulting in lines joining together followed by two newlines. Due to the presence of a static mutex, this also removes inline on the function.
This commit is contained in:
@@ -277,14 +277,17 @@ string CurrentDateTimeString()
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline void LogString(fstream &logFile, const char *timeString,
|
||||
char *str, int log_level)
|
||||
static void LogString(fstream &logFile, const char *timeString, char *str,
|
||||
int log_level)
|
||||
{
|
||||
static mutex logfile_mutex;
|
||||
string msg;
|
||||
msg += timeString;
|
||||
msg += str;
|
||||
|
||||
logfile_mutex.lock();
|
||||
logFile << msg << endl;
|
||||
logfile_mutex.unlock();
|
||||
|
||||
if (!!obsLogViewer)
|
||||
QMetaObject::invokeMethod(obsLogViewer.data(), "AddLine",
|
||||
|
||||
Reference in New Issue
Block a user