Ticket #9927: DRB-leak.patch

File DRB-leak.patch, 3.6 KB (added by Tony Lill <ajlill@…>, 8 years ago)
  • mythtv/libs/libmythtv/DeviceReadBuffer.cpp

    diff --git a/mythtv/libs/libmythtv/DeviceReadBuffer.cpp b/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
    index 2e1dfbc..f27c015 100644
    a b using namespace std; 
    1919
    2020DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll)
    2121    : videodevice(QString::null),   _stream_fd(-1),
    22       readerPausedCB(cb),
     22      readerPausedCB(cb),           thread(NULL),
    2323
    2424      // Data for managing the device ringbuffer
    2525      run(false),                   running(false),
    DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll) 
    3535
    3636      // statistics
    3737      max_used(0),                  avg_used(0),
    38       avg_cnt(0),                   thread(NULL)
     38      avg_cnt(0)
    3939{
    4040}
    4141
    DeviceReadBuffer::~DeviceReadBuffer() 
    4343{
    4444    if (buffer)
    4545        delete[] buffer;
     46    if (thread)
     47      Stop();
    4648}
    4749
    4850bool DeviceReadBuffer::Setup(const QString &streamName, int streamfd)
    bool DeviceReadBuffer::Setup(const QString &streamName, int streamfd) 
    9496
    9597void DeviceReadBuffer::Start(void)
    9698{
    97     bool was_running;
     99    QMutexLocker locker(&thread_lock);
    98100
    99101    {
    100102        QMutexLocker locker(&lock);
    101         was_running = running;
    102103        error = false;
    103104    }
    104105
    105     if (was_running)
     106    if (thread)
    106107    {
    107108        VERBOSE(VB_IMPORTANT, LOC_ERR + "Start(): Already running.");
    108109        SetRequestPause(false);
    void DeviceReadBuffer::Reset(const QString &streamName, int streamfd) 
    135136
    136137void DeviceReadBuffer::Stop(void)
    137138{
    138     bool was_running = IsRunning();
    139 
    140     if (!was_running)
     139    QMutexLocker locker(&thread_lock);
     140    if (!thread)
    141141    {
    142142        VERBOSE(VB_IMPORTANT, LOC + "Stop(): Not running.");
     143        return;
    143144    }
    144145
    145146    {
    void DeviceReadBuffer::Stop(void) 
    147148        run = false;
    148149    }
    149150
    150     if ( thread ) {
    151       pthread_join(thread, NULL);
    152       thread = (pthread_t)NULL;
    153     }
     151    pthread_join(thread, NULL);
     152    thread = (pthread_t)NULL;
    154153}
    155154
    156155void DeviceReadBuffer::SetRequestPause(bool req)
    uint DeviceReadBuffer::Read(unsigned char *buf, const uint count) 
    491490}
    492491
    493492/** \fn DeviceReadBuffer::WaitForUnused(uint) const
     493 *  \brief Return the amount of empty space in our internal buffer.
     494 *         If there is less than what is needed, and something is emptying the buffer, wait.
    494495 *  \param needed Number of bytes we want to write
    495496 *  \return bytes available for writing
    496497 */
    uint DeviceReadBuffer::WaitForUnused(uint needed) const 
    517518}
    518519
    519520/** \fn DeviceReadBuffer::WaitForUsed(uint) const
     521 *  \brief Return the number of bytes available in our buffer.
     522 *         Wait if another thread is actively  reading from the device.
    520523 *  \param needed Number of bytes we want to read
    521524 *  \return bytes available for reading
    522525 */
  • mythtv/libs/libmythtv/DeviceReadBuffer.h

    diff --git a/mythtv/libs/libmythtv/DeviceReadBuffer.h b/mythtv/libs/libmythtv/DeviceReadBuffer.h
    index 70fc262..84c1ba7 100644
    a b class DeviceReadBuffer 
    7878
    7979    ReaderPausedCB  *readerPausedCB;
    8080    pthread_t        thread;
     81    mutable QMutex   thread_lock;      // Manage access to thread variable
    8182
    8283    // Data for managing the device ringbuffer
    8384    mutable QMutex   lock;
    84     bool             run;
    85     bool             running;
     85    bool             run;              // Set to false if we want the thread to stop
     86    bool             running;          // If the read thread is running
    8687    bool             eof;
    8788    mutable bool     error;
    8889    bool             request_pause;