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:
parent
6d00146a2b
commit
77cbc36ad5
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user