Permalink
Browse files

Fixes #9927. Make sure we always join the pthread in the DeviceReadBu…

…ffer.

We didn't do this when the DRB exited on an error.
  • Loading branch information...
daniel-kristjansson committed Jul 25, 2011
1 parent 23305b9 commit 760c8db330134fbd4b084473bace157ea778aa27
Showing with 24 additions and 6 deletions.
  1. +11 −6 mythtv/libs/libmythtv/DeviceReadBuffer.cpp
  2. +13 −0 mythtv/libs/libmythtv/DeviceReadBuffer.h
@@ -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)
@@ -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;

0 comments on commit 760c8db

Please sign in to comment.