Skip to content

Commit

Permalink
Avoid high CPU usage in DB logger when DB is unavailable at startup.
Browse files Browse the repository at this point in the history
Commit [aab13b3] fixed a logic typo in the loop exit clause, but did not make a symetric change in the sleep
clause, so we sometimes enter a condition where the we were consuming 100% CPU waiting for the DB.
  • Loading branch information
daniel-kristjansson committed Jan 11, 2012
1 parent 2fe38e4 commit 3d170bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions mythtv/libs/libmythbase/logging.cpp
Expand Up @@ -524,20 +524,16 @@ void DBLoggerThread::run(void)
// Wait a bit before we start logging to the DB.. If we wait too long,
// then short-running tasks (like mythpreviewgen) will not log to the db
// at all, and that's undesirable.
bool ready = false;
while ( !aborted && ( !gCoreContext || !ready ) )
while (true)
{
ready = m_logger->isDatabaseReady();
if ((aborted || (gCoreContext && m_logger->isDatabaseReady())))
break;

// Don't delay if aborted was set while we were checking database ready
if (!ready && !aborted && !gCoreContext)
{
QMutexLocker qLock(&m_queueMutex);
m_wait->wait(qLock.mutex(), 100);
}
QMutexLocker locker(&m_queueMutex);
m_wait->wait(locker.mutex(), 100);
}

if (ready)
if (!aborted)
{
// We want the query to be out of scope before the RunEpilog() so
// shutdown occurs correctly as otherwise the connection appears still
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/logging.h
Expand Up @@ -134,7 +134,7 @@ class DBLoggerThread : public MThread
QMutex m_queueMutex;
QQueue<LoggingItem *> *m_queue;
QWaitCondition *m_wait; // protected by m_queueMutex
bool aborted; // protected by m_queueMutex
volatile bool aborted; // protected by m_queueMutex
};

#endif
Expand Down

0 comments on commit 3d170bf

Please sign in to comment.