Skip to content

Commit

Permalink
libcore|LogBuffer: Defer creation of the autoflush timer
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent e8ccafd commit 1462eb0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions doomsday/libs/core/src/core/logbuffer.cpp
Expand Up @@ -58,7 +58,7 @@ DE_PIMPL(LogBuffer)
EntryList entries;
EntryList toBeFlushed;
Time lastFlushedAt;
Timer autoFlushTimer;
std::unique_ptr<Timer> autoFlushTimer;
Sinks sinks;

Impl(Public *i, duint maxEntryCount)
Expand All @@ -77,7 +77,6 @@ DE_PIMPL(LogBuffer)
// , errSink(QtWarningMsg)
//#endif
, lastFlushedAt(Time::invalidTime())
// , autoFlushTimer(0)
{
// Standard output enabled by default.
outSink.setMode(LogSink::OnlyNormalEntries);
Expand All @@ -89,7 +88,7 @@ DE_PIMPL(LogBuffer)

~Impl()
{
autoFlushTimer.stop();
if (autoFlushTimer) autoFlushTimer->stop();
delete fileLogSink;
}

Expand All @@ -98,15 +97,20 @@ DE_PIMPL(LogBuffer)
DE_ASSERT(App::appExists());
if (yes)
{
if (!autoFlushTimer.isActive())
if (!autoFlushTimer)
{
autoFlushTimer.reset(new Timer);
autoFlushTimer->audienceForTrigger() += [this]() { self().flush(); };
}
if (!autoFlushTimer->isActive())
{
// Every now and then the buffer will be flushed.
autoFlushTimer.start(FLUSH_INTERVAL);
autoFlushTimer->start(FLUSH_INTERVAL);
}
}
else
{
autoFlushTimer.stop();
autoFlushTimer->stop();
}
}

Expand Down Expand Up @@ -149,9 +153,7 @@ LogBuffer *LogBuffer::_appBuffer = nullptr;

LogBuffer::LogBuffer(duint maxEntryCount)
: d(new Impl(this, maxEntryCount))
{
d->autoFlushTimer.audienceForTrigger() += [this]() { flush(); };
}
{}

LogBuffer::~LogBuffer()
{
Expand Down Expand Up @@ -259,7 +261,8 @@ void LogBuffer::enableFlushing(bool yes)
void LogBuffer::setAutoFlushInterval(const TimeSpan &interval)
{
enableFlushing();
d->autoFlushTimer.setInterval(interval);
DE_ASSERT(d->autoFlushTimer);
d->autoFlushTimer->setInterval(interval);
}

void LogBuffer::setOutputFile(String const &path, OutputChangeBehavior behavior)
Expand Down

0 comments on commit 1462eb0

Please sign in to comment.