# HG changeset patch # User Chris Cannam # Date 1404211149 -3600 # Node ID 90e9a3f873cf9860b1e97e16a729479d9e08eb4d # Parent 24964a8b31e737aa2023981e2eeaad4122062781 endl to qDebug does not seem to be threadsafe diff -r 24964a8b31e7 -r 90e9a3f873cf base/Debug.cpp --- a/base/Debug.cpp Mon Jun 30 15:02:43 2014 +0100 +++ b/base/Debug.cpp Tue Jul 01 11:39:09 2014 +0100 @@ -34,14 +34,16 @@ static QDebug *debug = 0; static QMutex mutex; static char *prefix; + mutex.lock(); + if (!debug) { prefix = new char[20]; sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid()); QString pfx = ResourceFinder().getUserResourcePrefix(); QDir logdir(QString("%1/%2").arg(pfx).arg("log")); if (!logdir.exists()) logdir.mkpath(logdir.path()); - logFile = new QFile(logdir.path() + "/debug.log"); + logFile = new QFile(logdir.path() + "/sv-debug.log"); if (logFile->open(QIODevice::WriteOnly | QIODevice::Truncate)) { QDebug(QtDebugMsg) << (const char *)prefix << "Opened debug log file " @@ -59,10 +61,12 @@ *debug << endl << (const char *)prefix << "Log started at " << QDateTime::currentDateTime().toString(); } - mutex.unlock(); QDebug &dref = *debug; - return dref << endl << (const char *)prefix; + dref << endl << (const char *)prefix; + + mutex.unlock(); + return dref; } QDebug &