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"
|
#include "rawhid_const.h"
|
||||||
|
|
||||||
|
// ***************************************
|
||||||
|
|
||||||
RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid) :
|
RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid) :
|
||||||
QThread(rawhid), // Pip
|
QThread(rawhid), // Pip
|
||||||
m_rawhid(rawhid),
|
m_rawhid(rawhid),
|
||||||
m_running(true)
|
m_running(true)
|
||||||
{
|
{
|
||||||
|
connect(m_rawhid, SLOT(destroyed(QObject *)), this, SLOT(onRawHidConnectionDestroyed(QObject *))); // Pip
|
||||||
}
|
}
|
||||||
|
|
||||||
RawHIDEnumerationThread::~RawHIDEnumerationThread()
|
RawHIDEnumerationThread::~RawHIDEnumerationThread()
|
||||||
@ -53,6 +55,16 @@ RawHIDEnumerationThread::~RawHIDEnumerationThread()
|
|||||||
qDebug() << "Cannot terminate 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()
|
void RawHIDEnumerationThread::run()
|
||||||
{
|
{
|
||||||
QStringList devices = m_rawhid->availableDevices();
|
QStringList devices = m_rawhid->availableDevices();
|
||||||
@ -61,8 +73,10 @@ void RawHIDEnumerationThread::run()
|
|||||||
|
|
||||||
while (m_running)
|
while (m_running)
|
||||||
{
|
{
|
||||||
|
mutex.lock(); // Pip
|
||||||
|
|
||||||
// update available devices every second (doesn't need more)
|
// 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;
|
counter = 0;
|
||||||
|
|
||||||
@ -74,10 +88,13 @@ void RawHIDEnumerationThread::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex.unlock(); // Pip
|
||||||
|
|
||||||
msleep(10);
|
msleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***************************************
|
||||||
|
|
||||||
RawHIDConnection::RawHIDConnection()
|
RawHIDConnection::RawHIDConnection()
|
||||||
: m_enumerateThread(this)
|
: m_enumerateThread(this)
|
||||||
|
@ -58,9 +58,15 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void enumerationChanged();
|
void enumerationChanged();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void onRawHidConnectionDestroyed(QObject *obj); // Pip
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RawHIDConnection *m_rawhid;
|
RawHIDConnection *m_rawhid;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user