Skip to content

Commit

Permalink
Fixes #9927. Make sure we always join the pthread in the DeviceReadBu…
Browse files Browse the repository at this point in the history
…ffer.

We didn't do this when the DRB exited on an error.
  • Loading branch information
daniel-kristjansson committed Jul 26, 2011
1 parent 23305b9 commit 760c8db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mythtv/libs/libmythtv/DeviceReadBuffer.cpp
Expand Up @@ -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),
Expand All @@ -41,6 +41,8 @@ DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll)

DeviceReadBuffer::~DeviceReadBuffer()
{
if (thread_exists)
Stop();
if (buffer)
delete[] buffer;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -151,6 +155,7 @@ void DeviceReadBuffer::Stop(void)
}

pthread_join(thread, NULL);
thread_exists = false;
}

void DeviceReadBuffer::SetRequestPause(bool req)
Expand Down
13 changes: 13 additions & 0 deletions mythtv/libs/libmythtv/DeviceReadBuffer.h
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 760c8db

Please sign in to comment.