Skip to content

Commit

Permalink
libdeng2: Initialize internal::Logs the first time a Log is used
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 6, 2012
1 parent 5e2f924 commit 1e3262d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions doomsday/libdeng2/src/core/log.cpp
Expand Up @@ -28,7 +28,6 @@
#include <QTextStream>
#include <QThread>
#include <QStringList>
#include <QDebug>

namespace de {

Expand Down Expand Up @@ -353,10 +352,16 @@ LogEntry &Log::enter(LogEntry::Level level, String const &format, LogEntry::Args
return *entry;
}

Log &Log::threadLog()
static internal::Logs &theLogs()
{
if(!logsPtr.get()) logsPtr.reset(new internal::Logs);
internal::Logs& logs = *logsPtr;
return *logsPtr;
}

Log &Log::threadLog()
{
internal::Logs &logs = theLogs();

DENG2_GUARD(logs);

// Each thread has its own log.
Expand All @@ -366,7 +371,6 @@ Log &Log::threadLog()
{
// Create a new log.
Log* theLog = new Log;
qDebug() << "Log" << theLog << "created for thread" << thread;
logs.insert(thread, theLog);
return *theLog;
}
Expand All @@ -378,8 +382,8 @@ Log &Log::threadLog()

void Log::disposeThreadLog()
{
if(!logsPtr.get()) logsPtr.reset(new internal::Logs);
internal::Logs& logs = *logsPtr;
internal::Logs &logs = theLogs();

DENG2_GUARD(logs);

QThread *thread = QThread::currentThread();
Expand Down

0 comments on commit 1e3262d

Please sign in to comment.