Skip to content

Commit

Permalink
Add mutex protection on the db logging queue
Browse files Browse the repository at this point in the history
Just to be sure.  QQueue isn't threadsafe.  Why play with fire?
  • Loading branch information
Beirdo committed May 29, 2011
1 parent a6e9e5e commit d3675b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mythtv/libs/libmythbase/mythlogging.cpp
Expand Up @@ -314,24 +314,32 @@ void DBLoggerThread::run(void)

aborted = false;

QMutexLocker qLock(&m_queueMutex);

while(!aborted || !m_queue->isEmpty())
{
if (m_queue->isEmpty())
{
qLock.unlock();
msleep(100);
qLock.relock();
continue;
}

item = m_queue->dequeue();
if (!item)
continue;

qLock.unlock();

if( item->message && !aborted )
{
m_logger->logqmsg(item);
}

deleteItem(item);

qLock.relock();
}
}

Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythbase/mythlogging.h
Expand Up @@ -5,6 +5,8 @@
#include <QString>
#include <QThread>
#include <QQueue>
#include <QMutex>
#include <QMutexLocker>
#endif
#include <stdint.h>
#include <time.h>
Expand Down Expand Up @@ -175,11 +177,13 @@ class DBLoggerThread : public QThread {
void stop(void) { aborted = true; }
bool enqueue(LoggingItem_t *item)
{
QMutexLocker qLock(&m_queueMutex);
m_queue->enqueue(item);
return true;
}
private:
DatabaseLogger *m_logger;
QMutex m_queueMutex;
QQueue<LoggingItem_t *> *m_queue;
bool aborted;
};
Expand Down

0 comments on commit d3675b5

Please sign in to comment.