summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kristjansson <danielk@cuymedia.net>2011-07-25 22:15:18 (GMT)
committer Daniel Kristjansson <danielk@cuymedia.net>2011-07-26 13:29:39 (GMT)
commit760c8db330134fbd4b084473bace157ea778aa27 (patch)
treebf6d8985bb9125d99dc69697d5acbf29d957a94f
parent23305b9ca1195f65c3c4f6ebe49e730522dafcaa (diff)
Fixes #9927. Make sure we always join the pthread in the DeviceReadBuffer.
We didn't do this when the DRB exited on an error.
-rw-r--r--mythtv/libs/libmythtv/DeviceReadBuffer.cpp17
-rw-r--r--mythtv/libs/libmythtv/DeviceReadBuffer.h13
2 files changed, 24 insertions, 6 deletions
diff --git a/mythtv/libs/libmythtv/DeviceReadBuffer.cpp b/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
index 8c7128b..dad079d 100644
--- a/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
+++ b/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
@@ -19,7 +19,7 @@ using namespace std;
DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll)
: videodevice(""), _stream_fd(-1),
- readerPausedCB(cb),
+ readerPausedCB(cb), thread_exists(false),
// Data for managing the device ringbuffer
run(false), running(false),
@@ -41,6 +41,8 @@ DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll)
DeviceReadBuffer::~DeviceReadBuffer()
{
+ if (thread_exists)
+ Stop();
if (buffer)
delete[] buffer;
}
@@ -95,15 +97,14 @@ bool DeviceReadBuffer::Setup(const QString &streamName, int streamfd)
void DeviceReadBuffer::Start(void)
{
- bool was_running;
+ QMutexLocker locker(&thread_lock);
{
QMutexLocker locker(&lock);
- was_running = running;
error = false;
}
- if (was_running)
+ if (thread_exists)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Start(): Already running.");
SetRequestPause(false);
@@ -117,7 +118,10 @@ void DeviceReadBuffer::Start(void)
QMutexLocker locker(&lock);
error = true;
+ return;
}
+
+ thread_exists = true;
}
void DeviceReadBuffer::Reset(const QString &streamName, int streamfd)
@@ -137,9 +141,9 @@ void DeviceReadBuffer::Reset(const QString &streamName, int streamfd)
void DeviceReadBuffer::Stop(void)
{
- bool was_running = IsRunning();
+ QMutexLocker locker(&thread_lock);
- if (!was_running)
+ if (!thread_exists)
{
VERBOSE(VB_IMPORTANT, LOC + "Stop(): Not running.");
return;
@@ -151,6 +155,7 @@ void DeviceReadBuffer::Stop(void)
}
pthread_join(thread, NULL);
+ thread_exists = false;
}
void DeviceReadBuffer::SetRequestPause(bool req)
diff --git a/mythtv/libs/libmythtv/DeviceReadBuffer.h b/mythtv/libs/libmythtv/DeviceReadBuffer.h
index 70fc262..bb4a271 100644
--- a/mythtv/libs/libmythtv/DeviceReadBuffer.h
+++ b/mythtv/libs/libmythtv/DeviceReadBuffer.h
@@ -13,6 +13,12 @@
#include "util.h"
+// Locking order
+//
+// thread_lock -> lock
+//
+// See tv_play.h for an explanation of locking order.
+
class ReaderPausedCB
{
protected:
@@ -77,11 +83,18 @@ class DeviceReadBuffer
int _stream_fd;
ReaderPausedCB *readerPausedCB;
+
+ // Manage access to thread variable
+ mutable QMutex thread_lock;
+ /// True if a thread has been created and needs reaping
+ bool thread_exists;
pthread_t thread;
// Data for managing the device ringbuffer
mutable QMutex lock;
+ /// true when we want the thread to be running
bool run;
+ /// true if the read thread is doing work
bool running;
bool eof;
mutable bool error;