Skip to content

Commit

Permalink
Fix jobqueue thread shutdown
Browse files Browse the repository at this point in the history
Originally, this had a pthread_testcancel in the thread, and pthread_cancel in
the controlling code.  I have changed this to get the same sort of controlled
thread shutdown that it used to have by putting in a flag for "processQueue".
When you want to exit that thread, tell it not to process anymore, and next
time the thread loops, it will exit (just like before with the testcancel at
the head of the loop).
  • Loading branch information
Beirdo committed Mar 5, 2011
1 parent 7c0a238 commit c4927c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mythtv/libs/libmythtv/jobqueue.cpp
Expand Up @@ -54,6 +54,7 @@ JobQueue::JobQueue(bool master)
jobsRunning = 0;

#ifndef USING_VALGRIND
processQueue = false;
queueThreadCondLock.lock();
queueThread.SetParent(this);
queueThread.start();
Expand All @@ -69,7 +70,7 @@ JobQueue::JobQueue(bool master)

JobQueue::~JobQueue(void)
{
queueThread.terminate();
processQueue = false;
queueThread.wait();

gCoreContext->removeListener(this);
Expand Down Expand Up @@ -147,6 +148,8 @@ void JobQueue::RunQueueProcessor(void)
queueThreadCond.wakeAll();
queueThreadCondLock.unlock();

processQueue = true;

RecoverQueue();

sleep(10);
Expand Down Expand Up @@ -183,7 +186,7 @@ void JobQueue::ProcessQueue(void)
bool startedJobAlready = false;
QMap<int, RunningJobInfo>::Iterator rjiter;

for (;;)
while (processQueue)
{
startedJobAlready = false;
sleepTime = gCoreContext->GetNumSetting("JobQueueCheckFrequency", 30);
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/jobqueue.h
Expand Up @@ -260,6 +260,7 @@ class MTV_PUBLIC JobQueue : public QObject
QueueProcessorThread queueThread;
QWaitCondition queueThreadCond;
QMutex queueThreadCondLock;
bool processQueue;
};

#endif
Expand Down

0 comments on commit c4927c2

Please sign in to comment.