Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 760c8db330134fbd4b084473bace157ea778aa27 1 parent 23305b9
daniel-kristjansson daniel-kristjansson authored
17 mythtv/libs/libmythtv/DeviceReadBuffer.cpp
@@ -19,7 +19,7 @@ using namespace std;
19 19
20 20 DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll)
21 21 : videodevice(""), _stream_fd(-1),
22   - readerPausedCB(cb),
  22 + readerPausedCB(cb), thread_exists(false),
23 23
24 24 // Data for managing the device ringbuffer
25 25 run(false), running(false),
@@ -41,6 +41,8 @@ DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll)
41 41
42 42 DeviceReadBuffer::~DeviceReadBuffer()
43 43 {
  44 + if (thread_exists)
  45 + Stop();
44 46 if (buffer)
45 47 delete[] buffer;
46 48 }
@@ -95,15 +97,14 @@ bool DeviceReadBuffer::Setup(const QString &streamName, int streamfd)
95 97
96 98 void DeviceReadBuffer::Start(void)
97 99 {
98   - bool was_running;
  100 + QMutexLocker locker(&thread_lock);
99 101
100 102 {
101 103 QMutexLocker locker(&lock);
102   - was_running = running;
103 104 error = false;
104 105 }
105 106
106   - if (was_running)
  107 + if (thread_exists)
107 108 {
108 109 VERBOSE(VB_IMPORTANT, LOC_ERR + "Start(): Already running.");
109 110 SetRequestPause(false);
@@ -117,7 +118,10 @@ void DeviceReadBuffer::Start(void)
117 118
118 119 QMutexLocker locker(&lock);
119 120 error = true;
  121 + return;
120 122 }
  123 +
  124 + thread_exists = true;
121 125 }
122 126
123 127 void DeviceReadBuffer::Reset(const QString &streamName, int streamfd)
@@ -137,9 +141,9 @@ void DeviceReadBuffer::Reset(const QString &streamName, int streamfd)
137 141
138 142 void DeviceReadBuffer::Stop(void)
139 143 {
140   - bool was_running = IsRunning();
  144 + QMutexLocker locker(&thread_lock);
141 145
142   - if (!was_running)
  146 + if (!thread_exists)
143 147 {
144 148 VERBOSE(VB_IMPORTANT, LOC + "Stop(): Not running.");
145 149 return;
@@ -151,6 +155,7 @@ void DeviceReadBuffer::Stop(void)
151 155 }
152 156
153 157 pthread_join(thread, NULL);
  158 + thread_exists = false;
154 159 }
155 160
156 161 void DeviceReadBuffer::SetRequestPause(bool req)
13 mythtv/libs/libmythtv/DeviceReadBuffer.h
@@ -13,6 +13,12 @@
13 13
14 14 #include "util.h"
15 15
  16 +// Locking order
  17 +//
  18 +// thread_lock -> lock
  19 +//
  20 +// See tv_play.h for an explanation of locking order.
  21 +
16 22 class ReaderPausedCB
17 23 {
18 24 protected:
@@ -77,11 +83,18 @@ class DeviceReadBuffer
77 83 int _stream_fd;
78 84
79 85 ReaderPausedCB *readerPausedCB;
  86 +
  87 + // Manage access to thread variable
  88 + mutable QMutex thread_lock;
  89 + /// True if a thread has been created and needs reaping
  90 + bool thread_exists;
80 91 pthread_t thread;
81 92
82 93 // Data for managing the device ringbuffer
83 94 mutable QMutex lock;
  95 + /// true when we want the thread to be running
84 96 bool run;
  97 + /// true if the read thread is doing work
85 98 bool running;
86 99 bool eof;
87 100 mutable bool error;

0 comments on commit 760c8db

Please sign in to comment.
Something went wrong with that request. Please try again.