Ticket #9867: 0046-mheg-Use-a-shared-mutex-to-control-access-to-QWaitCo.patch

File 0046-mheg-Use-a-shared-mutex-to-control-access-to-QWaitCo.patch, 4.1 KB (added by Lawrence Rust <lvr@…>, 13 years ago)
  • mythtv/libs/libmythtv/mhi.cpp

    From f2bdad6dc02998c6c2e739d6fa9bf413dc562e12 Mon Sep 17 00:00:00 2001
    From: Lawrence Rust <lvr@softsystem.co.uk>
    Date: Fri, 24 Jun 2011 18:35:08 +0200
    Subject: [PATCH 46/47] mheg: Use a shared mutex to control access to QWaitCondition
    
    This prevents spurious hangs in the mheg code when waiting for an absent file
    to arrive.
    
    Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
    ---
     mythtv/libs/libmythtv/mhi.cpp |   29 ++++++++++++++---------------
     mythtv/libs/libmythtv/mhi.h   |    1 +
     2 files changed, 15 insertions(+), 15 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/mhi.cpp b/mythtv/libs/libmythtv/mhi.cpp
    index 81163ae..82c6608 100644
    a b void MHIContext::StopEngine() 
    146146        while (!m_stopped)
    147147        {
    148148            m_stop = true;
    149             m_engine_wait.wakeAll();
     149            {QMutexLocker locker(&m_engineLock);
     150            m_engine_wait.wakeAll();}
    150151            usleep(1000);
    151152        }
    152153        pthread_join(m_engineThread, NULL);
    void *MHIContext::StartMHEGEngine(void *param) 
    234235
    235236void MHIContext::RunMHEGEngine(void)
    236237{
    237     // Qt4 requires a QMutex as a parameter...
    238     // not sure if this is the best solution.  Mutex Must be locked before wait.
    239     QMutex mutex;
    240     mutex.lock();
    241 
    242238    while (!m_stop)
    243239    {
    244240        int toWait;
    void MHIContext::RunMHEGEngine(void) 
    268264        if (toWait > 1000 || toWait <= 0)
    269265            toWait = 1000;
    270266
    271         m_engine_wait.wait(&mutex, toWait);
     267        QMutexLocker locker(&m_engineLock);
     268        m_engine_wait.wait(&m_engineLock, toWait);
    272269    }
    273270}
    274271
    void MHIContext::QueueDSMCCPacket( 
    309306        return;
    310307
    311308    memcpy(dataCopy, data, length*sizeof(unsigned char));
    312     QMutexLocker locker(&m_dsmccLock);
     309    {QMutexLocker locker(&m_dsmccLock);
    313310    m_dsmccQueue.enqueue(new DSMCCPacket(dataCopy,     length,
    314311                                         componentTag, carouselId,
    315                                          dataBroadcastId));
     312                                         dataBroadcastId));}
     313    QMutexLocker locker(&m_engineLock);
    316314    m_engine_wait.wakeAll();
    317315}
    318316
    void MHIContext::SetNetBootInfo(const unsigned char *data, uint length) 
    333331    if (m_lastNbiVersion == NBI_VERSION_UNSET)
    334332        m_lastNbiVersion = data[0];
    335333    else
     334    {
     335        QMutexLocker locker(&m_engineLock);
    336336        m_engine_wait.wakeAll();
     337    }
    337338}
    338339
    339340void MHIContext::NetworkBootRequested(void)
    bool MHIContext::GetCarouselData(QString objectPath, QByteArray &result) 
    380381    // same thread this is safe.  Otherwise we need to make a deep copy of
    381382    // the result.
    382383
    383     // Qt4 requires a QMutex as a parameter...
    384     // not sure if this is the best solution.  Mutex Must be locked before wait.
    385     QMutex mutex;
    386     mutex.lock();
    387 
    388384    while (!m_stop)
    389385    {
    390386        int res = m_dsmcc->GetDSMCCObject(path, result);
    bool MHIContext::GetCarouselData(QString objectPath, QByteArray &result) 
    397393        // some more packets.  We should eventually find out if this item is
    398394        // present.
    399395        ProcessDSMCCQueue();
    400         m_engine_wait.wait(&mutex, 1000);
     396        QMutexLocker locker(&m_engineLock);
     397        m_engine_wait.wait(&m_engineLock, 1000);
    401398    }
    402399    return false; // Stop has been set.  Say the object isn't present.
    403400}
    bool MHIContext::OfferKey(QString key) 
    475472        m_keyQueue.enqueue(action);
    476473        VERBOSE(VB_IMPORTANT, "Adding MHEG key "<<key<<":"<<action
    477474                <<":"<<m_keyQueue.size());
     475        locker.unlock();
     476        QMutexLocker locker2(&m_engineLock);
    478477        m_engine_wait.wakeAll();
    479478        return true;
    480479    }
  • mythtv/libs/libmythtv/mhi.h

    diff --git a/mythtv/libs/libmythtv/mhi.h b/mythtv/libs/libmythtv/mhi.h
    index 63bae67..3920ae3 100644
    a b class MHIContext : public MHContext 
    159159    MHEG            *m_engine; // Pointer to the MHEG engine
    160160
    161161    QWaitCondition   m_engine_wait;
     162    QMutex           m_engineLock;
    162163    bool             m_stop;
    163164    bool             m_stopped;
    164165    QMutex           m_display_lock;