Mercurial > hg > svcore
diff base/Debug.cpp @ 938:90e9a3f873cf
endl to qDebug does not seem to be threadsafe
author | Chris Cannam |
---|---|
date | Tue, 01 Jul 2014 11:39:09 +0100 |
parents | 2010409af203 |
children | 387fa69f4eaa |
line wrap: on
line diff
--- 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 &