Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rework logserver startup to remove race condition
Seems the loggingthread and logserverthread were in a race condition that
would show itself as a deadlock nearly always on my development box, but never
on my production box.
  • Loading branch information
Beirdo committed Jul 21, 2012
1 parent 8e96e2e commit 3d4467d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mythtv/libs/libmythbase/loggingserver.cpp
Expand Up @@ -63,7 +63,7 @@ LogForwardThread *logForwardThread = NULL;
static QMutex logThreadStartedMutex;
static QWaitCondition logThreadStarted;
static bool logThreadFinished = false;
static bool logThreadStarting = false;
static bool logThreadStarting = true;

typedef QList<LoggerBase *> LoggerList;

Expand Down Expand Up @@ -818,6 +818,7 @@ void LogServerThread::run(void)
this, SLOT(pingClient(QString)), Qt::QueuedConnection);

// cerr << "wake all" << endl;
logThreadStarting = false;
locker.unlock();
logThreadStarted.wakeAll();
// cerr << "unlock" << endl;
Expand Down Expand Up @@ -859,6 +860,7 @@ void LogServerThread::run(void)
if (abortThread)
{
// cerr << "wake all" << endl;
logThreadStarting = false;
locker.unlock();
logThreadStarted.wakeAll();
qApp->processEvents();
Expand Down Expand Up @@ -952,11 +954,11 @@ bool logServerStart(void)
if (logServerThread && logServerThread->isRunning())
return true;

logThreadStarting = true;

if (!logServerThread)
logServerThread = new LogServerThread();

logThreadStarting = true;

// cerr << "starting server" << endl;
QMutexLocker locker(&logThreadStartedMutex);
logServerThread->start();
Expand Down Expand Up @@ -989,9 +991,7 @@ void logServerWait(void)
{
// cerr << "waiting" << endl;
QMutexLocker locker(&logThreadStartedMutex);
while ((!logThreadStarting ||
(logServerThread && logServerThread->isRunning())) &&
!logThreadStarted.wait(locker.mutex(), 100));
while (!logThreadStarted.wait(locker.mutex(), 100) && logThreadStarting);
locker.unlock();
// cerr << "done waiting" << endl;
}
Expand Down

0 comments on commit 3d4467d

Please sign in to comment.