diff --git a/mythtv/libs/libmythbase/bonjourregister.cpp b/mythtv/libs/libmythbase/bonjourregister.cpp index 07ac0887931..dd699695dc2 100644 --- a/mythtv/libs/libmythbase/bonjourregister.cpp +++ b/mythtv/libs/libmythbase/bonjourregister.cpp @@ -8,10 +8,10 @@ #define LOC QString("Bonjour: ") -QMutex BonjourRegister::m_lock; +QMutex BonjourRegister::g_lock; BonjourRegister::BonjourRegister(QObject *parent) - : QObject(parent), m_dnssref(0), m_socket(NULL), m_haslock(false) + : QObject(parent), m_dnssref(0), m_socket(NULL), m_lock(NULL) { setenv("AVAHI_COMPAT_NOWARN", "1", 1); } @@ -32,11 +32,8 @@ BonjourRegister::~BonjourRegister() m_socket->deleteLater(); m_socket = NULL; - - if (m_haslock) - { - m_lock.unlock(); - } + delete m_lock; + m_lock = NULL; } bool BonjourRegister::Register(uint16_t port, const QByteArray &type, @@ -48,8 +45,7 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type, return true; } - m_lock.lock(); - m_haslock = true; + m_lock = new QMutexLocker(&g_lock); uint16_t qport = qToBigEndian(port); DNSServiceErrorType res = @@ -71,13 +67,15 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type, m_socket->setEnabled(true); connect(m_socket, SIGNAL(activated(int)), this, SLOT(socketReadyRead())); + delete m_lock; // would already have been deleted, but just in case + m_lock = NULL; return true; } } LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service."); - m_haslock = false; - m_lock.unlock(); + delete m_lock; + m_lock = NULL; return false; } @@ -100,8 +98,9 @@ void BonjourRegister::BonjourCallback(DNSServiceRef ref, DNSServiceFlags flags, (void)flags; BonjourRegister *bonjour = static_cast(object); - bonjour->m_haslock = false; - bonjour->m_lock.unlock(); + delete bonjour->m_lock; + bonjour->m_lock = NULL; + if (kDNSServiceErr_NoError != errorcode) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Callback Error: %1") diff --git a/mythtv/libs/libmythbase/bonjourregister.h b/mythtv/libs/libmythbase/bonjourregister.h index 96f951eaba5..65affe5d57d 100644 --- a/mythtv/libs/libmythbase/bonjourregister.h +++ b/mythtv/libs/libmythbase/bonjourregister.h @@ -13,7 +13,7 @@ class MBASE_PUBLIC BonjourRegister : public QObject Q_OBJECT public: BonjourRegister(QObject *parent = 0); - ~BonjourRegister(); + virtual ~BonjourRegister(); bool Register(uint16_t port, const QByteArray &type, const QByteArray &name, const QByteArray &txt); @@ -32,7 +32,7 @@ class MBASE_PUBLIC BonjourRegister : public QObject const char *domain, void *object); DNSServiceRef m_dnssref; QSocketNotifier *m_socket; - static QMutex m_lock; - bool m_haslock; + QMutexLocker *m_lock; + static QMutex g_lock; }; #endif