Revert "Made buffer thread wait until there is a GUI client #4721"

This reverts commit 9a4327e44236c0ac30809660dc87a97e984dc84f.
This commit is contained in:
Jerry (Xinyu Hou) 2015-07-15 11:57:33 -07:00
parent 01526bbe78
commit 5ec9ccc76e
4 changed files with 16 additions and 20 deletions

View File

@ -37,7 +37,7 @@ enum EIpcLogOutputter {
kBufferRateTimeLimit = 1 // seconds
};
IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType, bool useThread) :
IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, bool useThread) :
m_ipcServer(ipcServer),
m_bufferMutex(ARCH->newMutex()),
m_sending(false),
@ -50,8 +50,7 @@ IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType
m_bufferRateWriteLimit(kBufferRateWriteLimit),
m_bufferRateTimeLimit(kBufferRateTimeLimit),
m_bufferWriteCount(0),
m_bufferRateStart(ARCH->time()),
m_clientType(clientType)
m_bufferRateStart(ARCH->time())
{
if (useThread) {
m_bufferThread = new Thread(new TMethodJob<IpcLogOutputter>(
@ -103,9 +102,7 @@ IpcLogOutputter::write(ELevel, const char* text)
}
appendBuffer(text);
if (m_ipcServer.hasClients(m_clientType)) {
notifyBuffer();
}
notifyBuffer();
return true;
}
@ -144,7 +141,7 @@ IpcLogOutputter::bufferThread(void*)
try {
while (m_running) {
if (m_buffer.empty() || !m_ipcServer.hasClients(m_clientType)) {
if (m_buffer.empty()) {
ArchMutexLock lock(m_notifyMutex);
ARCH->waitCondVar(m_notifyCond, m_notifyMutex, -1);
}
@ -187,7 +184,7 @@ IpcLogOutputter::getChunk(size_t count)
void
IpcLogOutputter::sendBuffer()
{
if (m_buffer.empty() || !m_ipcServer.hasClients(m_clientType)) {
if (m_buffer.empty() || !m_ipcServer.hasClients(kIpcClientGui)) {
return;
}

View File

@ -21,7 +21,6 @@
#include "arch/Arch.h"
#include "arch/IArchMultithread.h"
#include "base/ILogOutputter.h"
#include "ipc/Ipc.h"
#include <deque>
@ -40,7 +39,7 @@ public:
If \p useThread is \c false, then the buffer needs to be sent manually
using the \c sendBuffer() function.
*/
IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType, bool useThread);
IpcLogOutputter(IpcServer& ipcServer, bool useThread);
virtual ~IpcLogOutputter();
// ILogOutputter overrides
@ -114,5 +113,4 @@ private:
UInt16 m_bufferWriteCount;
double m_bufferRateStart;
bool m_useThread;
EIpcClientType m_clientType;
};

View File

@ -211,7 +211,7 @@ DaemonApp::mainLoop(bool logToFile)
m_ipcServer = new IpcServer(m_events, &multiplexer);
// send logging to gui via ipc, log system adopts outputter.
m_ipcLogOutputter = new IpcLogOutputter(*m_ipcServer, kIpcClientGui, true);
m_ipcLogOutputter = new IpcLogOutputter(*m_ipcServer, true);
CLOG->insert(m_ipcLogOutputter);
#if SYSAPI_WIN32

View File

@ -52,11 +52,11 @@ TEST(IpcLogOutputterTests, write_threadingEnabled_bufferIsSent)
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(5);
EXPECT_CALL(mockServer, hasClients(_)).Times(2);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 1\n"), _)).Times(1);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 2\n"), _)).Times(1);
IpcLogOutputter outputter(mockServer, kIpcClientUnknown, true);
IpcLogOutputter outputter(mockServer, true);
outputter.write(kNOTE, "mock 1");
mockServer.waitForSend();
outputter.write(kNOTE, "mock 2");
@ -68,10 +68,11 @@ TEST(IpcLogOutputterTests, write_overBufferMaxSize_firstLineTruncated)
MockIpcServer mockServer;
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(4);
EXPECT_CALL(mockServer, hasClients(_)).Times(1);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 2\nmock 3\n"), _)).Times(1);
IpcLogOutputter outputter(mockServer, kIpcClientUnknown, false);
IpcLogOutputter outputter(mockServer, false);
outputter.bufferMaxSize(2);
// log more lines than the buffer can contain
@ -87,10 +88,10 @@ TEST(IpcLogOutputterTests, write_underBufferMaxSize_allLinesAreSent)
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(3);
EXPECT_CALL(mockServer, hasClients(_)).Times(1);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 1\nmock 2\n"), _)).Times(1);
IpcLogOutputter outputter(mockServer, kIpcClientUnknown, false);
IpcLogOutputter outputter(mockServer, false);
outputter.bufferMaxSize(2);
// log more lines than the buffer can contain
@ -142,11 +143,11 @@ TEST(IpcLogOutputterTests, write_underBufferRateLimit_allLinesAreSent)
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(6);
EXPECT_CALL(mockServer, hasClients(_)).Times(2);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 1\nmock 2\n"), _)).Times(1);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 3\nmock 4\n"), _)).Times(1);
IpcLogOutputter outputter(mockServer, kIpcClientUnknown, false);
IpcLogOutputter outputter(mockServer, false);
outputter.bufferRateLimit(4, 1); // 1s (should be plenty of time)
// log 1 more line than the buffer can accept in time limit.