Ticket #13649: 20200714-masterkey.patch

File 20200714-masterkey.patch, 3.9 KB (added by Klaas de Waal, 5 months ago)

Create master key only once and use that each time the lock is requested instead of creating the key every time again.

  • mythtv/libs/libmythtv/recorders/dvbchannel.cpp

    diff --git a/mythtv/libs/libmythtv/recorders/dvbchannel.cpp b/mythtv/libs/libmythtv/recorders/dvbchannel.cpp
    index ba31daa1e3..0911d740e4 100644
    a b DVBChannel::DVBChannel(QString aDevice, TVRec *parent) 
    7777    : DTVChannel(parent), m_device(std::move(aDevice))
    7878{
    7979    s_master_map_lock.lockForWrite();
    80     QString key = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, m_device);
     80    m_key = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, m_device);
    8181    if (m_pParent)
    82         key += QString(":%1")
     82        m_key += QString(":%1")
    8383            .arg(CardUtil::GetSourceID(m_pParent->GetInputId()));
    84     s_master_map[key].push_back(this); // == RegisterForMaster
    85     auto *master = dynamic_cast<DVBChannel*>(s_master_map[key].front());
     84
     85    s_master_map[m_key].push_back(this); // == RegisterForMaster
     86    auto *master = dynamic_cast<DVBChannel*>(s_master_map[m_key].front());
    8687    if (master == this)
    8788    {
    8889        m_dvbCam = new DVBCam(m_device);
    DVBChannel::~DVBChannel() 
    103104    // set a new master if there are other instances and we're the master
    104105    // whether we are the master or not remove us from the map..
    105106    s_master_map_lock.lockForWrite();
    106     QString key = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, m_device);
    107     if (m_pParent)
    108         key += QString(":%1")
    109             .arg(CardUtil::GetSourceID(m_pParent->GetInputId()));
    110     auto *master = dynamic_cast<DVBChannel*>(s_master_map[key].front());
     107    auto *master = dynamic_cast<DVBChannel*>(s_master_map[m_key].front());
    111108    if (master == this)
    112109    {
    113         s_master_map[key].pop_front();
     110        s_master_map[m_key].pop_front();
    114111        DVBChannel *new_master = nullptr;
    115         if (!s_master_map[key].empty())
    116             new_master = dynamic_cast<DVBChannel*>(s_master_map[key].front());
     112        if (!s_master_map[m_key].empty())
     113            new_master = dynamic_cast<DVBChannel*>(s_master_map[m_key].front());
    117114        if (new_master)
    118115        {
    119116            QMutexLocker master_locker(&(master->m_hwLock));
    DVBChannel::~DVBChannel() 
    123120    }
    124121    else
    125122    {
    126         s_master_map[key].removeAll(this);
     123        s_master_map[m_key].removeAll(this);
    127124    }
    128125    s_master_map_lock.unlock();
    129126
    DVBChannel::~DVBChannel() 
    131128
    132129    // if we're the last one out delete dvbcam
    133130    s_master_map_lock.lockForRead();
    134     MasterMap::iterator mit = s_master_map.find(key);
     131    MasterMap::iterator mit = s_master_map.find(m_key);
    135132    if ((*mit).empty())
    136133        delete m_dvbCam;
    137134    m_dvbCam = nullptr;
    void DVBChannel::ReturnMasterLock(DVBChannel* &dvbm) 
    13581355
    13591356DVBChannel *DVBChannel::GetMasterLock(void) const
    13601357{
    1361     QString key = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, m_device);
    1362     if (m_pParent)
    1363         key += QString(":%1")
    1364             .arg(CardUtil::GetSourceID(m_pParent->GetInputId()));
    1365     DTVChannel *master = DTVChannel::GetMasterLock(key);
     1358    DTVChannel *master = DTVChannel::GetMasterLock(m_key);
    13661359    auto *dvbm = dynamic_cast<DVBChannel*>(master);
    13671360    if (master && !dvbm)
    13681361        DTVChannel::ReturnMasterLock(master);
  • mythtv/libs/libmythtv/recorders/dvbchannel.h

    diff --git a/mythtv/libs/libmythtv/recorders/dvbchannel.h b/mythtv/libs/libmythtv/recorders/dvbchannel.h
    index 2ce0898e4d..99caaabf3a 100644
    a b class DVBChannel : public DTVChannel 
    162162    // Other State
    163163                      /// File descriptor for tuning hardware
    164164    int               m_fdFrontend          {-1};
    165     QString           m_device;      ///< DVB Device
     165    QString           m_device;                 // DVB Device
     166    QString           m_key;                    // master lock key
    166167                      /// true iff our driver munges PMT
    167168    bool              m_hasCrcBug           {false};
    168169