Skip to content

Commit

Permalink
Fixed|Server: Threading issue with log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 17, 2017
1 parent 3e9cc61 commit bc38422
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions doomsday/apps/server/src/shelluser.cpp
Expand Up @@ -24,6 +24,7 @@
#include <de/Log>
#include <de/LogBuffer>
#include <de/LogSink>
#include <de/Loop>
#include <doomsday/console/exec.h>
#include <doomsday/console/knownword.h>
#include <doomsday/games.h>
Expand All @@ -41,7 +42,7 @@ using namespace de;
DENG2_PIMPL(ShellUser), public LogSink
{
/// Log entries to be sent are collected here.
shell::LogEntryPacket logEntryPacket;
LockableT<shell::LogEntryPacket> logEntryPacket;

Impl(Public &i) : Base(i)
{
Expand All @@ -56,7 +57,8 @@ DENG2_PIMPL(ShellUser), public LogSink

LogSink &operator << (LogEntry const &entry)
{
logEntryPacket.add(entry);
DENG2_GUARD(logEntryPacket);
logEntryPacket.value.add(entry);
return *this;
}

Expand All @@ -67,14 +69,19 @@ DENG2_PIMPL(ShellUser), public LogSink

/**
* Sends the accumulated log entries over the link.
* Note that any thread can flush the log sinks.
*/
void flush()
{
if (!logEntryPacket.isEmpty() && self().status() == shell::Link::Connected)
Loop::mainCall([this] ()
{
self() << logEntryPacket;
logEntryPacket.clear();
}
DENG2_GUARD(logEntryPacket);
if (!logEntryPacket.value.isEmpty() && self().status() == shell::Link::Connected)
{
self() << logEntryPacket.value;
logEntryPacket.value.clear();
}
});
}
};

Expand Down

0 comments on commit bc38422

Please sign in to comment.