Disabled threading on most IPC logging tests #4624

Threading was making it very hard to reliably run the IPC logging tests
(many timing issues), so I disabled threading for most of the tests.
This commit is contained in:
Nick Bolton
2015-05-20 17:42:07 +01:00
parent 89a977da66
commit 561204b2a7
6 changed files with 111 additions and 115 deletions

View File

@@ -37,11 +37,12 @@ enum EIpcLogOutputter {
kBufferRateTimeLimit = 1 // seconds
};
IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer) :
IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, bool useThread) :
m_ipcServer(ipcServer),
m_bufferMutex(ARCH->newMutex()),
m_sending(false),
m_running(true),
m_running(false),
m_bufferThread(nullptr),
m_notifyCond(ARCH->newCondVar()),
m_notifyMutex(ARCH->newMutex()),
m_bufferWaiting(false),
@@ -51,8 +52,10 @@ IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer) :
m_bufferWriteCount(0),
m_bufferRateStart(ARCH->time())
{
m_bufferThread = new Thread(new TMethodJob<IpcLogOutputter>(
this, &IpcLogOutputter::bufferThread));
if (useThread) {
m_bufferThread = new Thread(new TMethodJob<IpcLogOutputter>(
this, &IpcLogOutputter::bufferThread));
}
}
IpcLogOutputter::~IpcLogOutputter()
@@ -60,7 +63,10 @@ IpcLogOutputter::~IpcLogOutputter()
close();
ARCH->closeMutex(m_bufferMutex);
delete m_bufferThread;
if (m_bufferThread != nullptr) {
delete m_bufferThread;
}
ARCH->closeCondVar(m_notifyCond);
ARCH->closeMutex(m_notifyMutex);
@@ -74,9 +80,11 @@ IpcLogOutputter::open(const char* title)
void
IpcLogOutputter::close()
{
m_running = false;
notifyBuffer();
m_bufferThread->wait(5);
if (m_bufferThread != nullptr) {
m_running = false;
notifyBuffer();
m_bufferThread->wait(5);
}
}
void
@@ -85,27 +93,12 @@ IpcLogOutputter::show(bool showIfEmpty)
}
bool
IpcLogOutputter::write(ELevel level, const char* text)
IpcLogOutputter::write(ELevel, const char* text)
{
return write(level, text, false);
}
bool
IpcLogOutputter::write(ELevel, const char* text, bool force)
{
// TODO: discard based on thread id? hmm...
// sending the buffer generates log messages, which we must throw
// away (otherwise this would cause recursion). this is just a drawback
// of logging this way. there is also the risk that this could throw
// away log messages not generated by the ipc, but it seems like it
// would be difficult to distinguish (other than looking at the stack
// trace somehow). perhaps a file stream might be a better option :-/
if (m_sending && !force) {
// ignore events from the buffer thread (would cause recursion).
if (Thread::getCurrentThread().getID() == m_bufferThreadId) {
return true;
}
// ignore events from the buffer thread (would cause recursion).
if (m_bufferThread != nullptr &&
Thread::getCurrentThread().getID() == m_bufferThreadId) {
return true;
}
appendBuffer(text);
@@ -143,29 +136,17 @@ IpcLogOutputter::appendBuffer(const String& text)
void
IpcLogOutputter::bufferThread(void*)
{
ArchMutexLock lock(m_notifyMutex);
m_bufferThreadId = m_bufferThread->getID();
m_running = true;
try {
while (m_running) {
if (m_ipcServer.hasClients(kIpcClientGui)) {
// buffer is sent in chunks, so keep sending until it's
// empty (or the program has stopped in the meantime).
while (m_running && !m_buffer.empty()) {
sendBuffer();
}
if (m_buffer.empty()) {
ArchMutexLock lock(m_notifyMutex);
ARCH->waitCondVar(m_notifyCond, m_notifyMutex, -1);
}
// program may be stopping while we were in the send loop.
if (!m_running) {
break;
}
m_bufferWaiting = true;
ARCH->waitCondVar(m_notifyCond, m_notifyMutex, -1);
m_bufferWaiting = false;
sendBuffer();
}
}
catch (XArch& e) {
@@ -178,9 +159,6 @@ IpcLogOutputter::bufferThread(void*)
void
IpcLogOutputter::notifyBuffer()
{
if (!m_bufferWaiting) {
return;
}
ArchMutexLock lock(m_notifyMutex);
ARCH->broadcastCondVar(m_notifyCond);
}
@@ -206,8 +184,11 @@ IpcLogOutputter::getChunk(size_t count)
void
IpcLogOutputter::sendBuffer()
{
IpcLogLineMessage message(getChunk(kMaxSendLines));
if (m_buffer.empty() || !m_ipcServer.hasClients(kIpcClientGui)) {
return;
}
IpcLogLineMessage message(getChunk(kMaxSendLines));
m_sending = true;
m_ipcServer.send(message, kIpcClientGui);
m_sending = false;