Permalink
Browse files

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...
1 parent 8e96e2e commit 3d4467d4aafb0ad30a5afc95b4c83111d1ce001e @Beirdo Beirdo committed Jul 21, 2012
Showing with 6 additions and 6 deletions.
  1. +6 −6 mythtv/libs/libmythbase/loggingserver.cpp
@@ -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;
@@ -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;
@@ -859,6 +860,7 @@ void LogServerThread::run(void)
if (abortThread)
{
// cerr << "wake all" << endl;
+ logThreadStarting = false;
locker.unlock();
logThreadStarted.wakeAll();
qApp->processEvents();
@@ -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();
@@ -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;
}

0 comments on commit 3d4467d

Please sign in to comment.