Permalink
Browse files

Use QMutexLocker to lock BonjourRegister

Following 29fae07, use a QMutexLocker instead.
Rename static class member to follow MythTV coding style
  • Loading branch information...
jyavenard committed Jul 10, 2013
1 parent 4000137 commit a8ec95a23d1a6e39fa907ede8a2fe3a2c91ccb68
Showing with 15 additions and 16 deletions.
  1. +12 −13 mythtv/libs/libmythbase/bonjourregister.cpp
  2. +3 −3 mythtv/libs/libmythbase/bonjourregister.h
@@ -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<BonjourRegister *>(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")
@@ -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

0 comments on commit a8ec95a

Please sign in to comment.