1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-16 08:29:15 +01:00

Added object destroyed monitoring to the RawHIDEnumerationThread object to ensure it doesn't crash if it's parent (m_rawhid) is destroyed.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2888 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-02-26 12:56:14 +00:00 committed by pip
parent 6d00146a2b
commit 77cbc36ad5
2 changed files with 24 additions and 1 deletions

View File

@ -36,12 +36,14 @@
#include "rawhid_const.h"
// ***************************************
RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid) :
QThread(rawhid), // Pip
m_rawhid(rawhid),
m_running(true)
{
connect(m_rawhid, SLOT(destroyed(QObject *)), this, SLOT(onRawHidConnectionDestroyed(QObject *))); // Pip
}
RawHIDEnumerationThread::~RawHIDEnumerationThread()
@ -53,6 +55,16 @@ RawHIDEnumerationThread::~RawHIDEnumerationThread()
qDebug() << "Cannot terminate RawHIDEnumerationThread";
}
void RawHIDEnumerationThread::onRawHidConnectionDestroyed(QObject *obj) // Pip
{
QMutexLocker locker(&mutex);
if (!m_rawhid || m_rawhid != obj)
return;
m_rawhid = NULL;
}
void RawHIDEnumerationThread::run()
{
QStringList devices = m_rawhid->availableDevices();
@ -61,8 +73,10 @@ void RawHIDEnumerationThread::run()
while (m_running)
{
mutex.lock(); // Pip
// update available devices every second (doesn't need more)
if (++counter >= 100 && !m_rawhid->deviceOpened())
if (++counter >= 100 && m_rawhid && !m_rawhid->deviceOpened())
{
counter = 0;
@ -74,10 +88,13 @@ void RawHIDEnumerationThread::run()
}
}
mutex.unlock(); // Pip
msleep(10);
}
}
// ***************************************
RawHIDConnection::RawHIDConnection()
: m_enumerateThread(this)

View File

@ -58,9 +58,15 @@ public:
signals:
void enumerationChanged();
protected slots:
void onRawHidConnectionDestroyed(QObject *obj); // Pip
protected:
RawHIDConnection *m_rawhid;
bool m_running;
private:
QMutex mutex;
};