1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

Fix for issue OP-1108: Mutex not correctly released in GCS

This commit is contained in:
Bertrand Songis 2013-11-12 22:43:54 +01:00 committed by Alessio Morale
parent 82c05be41d
commit 117c2fb97f

View File

@ -205,6 +205,8 @@ qint64 RawHIDReadThread::getBytesAvailable()
return m_readBuffer.size();
}
// *********************************************************************************
RawHIDWriteThread::RawHIDWriteThread(RawHID *hid)
: m_hid(hid),
hiddev(&hid->dev),
@ -212,8 +214,6 @@ RawHIDWriteThread::RawHIDWriteThread(RawHID *hid)
m_running(true)
{}
// *********************************************************************************
RawHIDWriteThread::~RawHIDWriteThread()
{
m_running = false;
@ -227,9 +227,11 @@ void RawHIDWriteThread::run()
{
while (m_running) {
char buffer[WRITE_SIZE] = { 0 };
int size;
m_writeBufMtx.lock();
int size = qMin(WRITE_SIZE - 2, m_writeBuffer.size());
{
QMutexLocker lock(&m_writeBufMtx);
size = qMin(WRITE_SIZE - 2, m_writeBuffer.size());
while (size <= 0) {
// wait on new data to write condition, the timeout
// enable the thread to shutdown properly
@ -248,7 +250,7 @@ void RawHIDWriteThread::run()
memcpy(&buffer[2], m_writeBuffer.constData(), size);
buffer[1] = size; // valid data length
buffer[0] = 2; // reportID
m_writeBufMtx.unlock();
}
// must hold lock through the send to know how much was sent
int ret = hiddev->send(hidno, buffer, WRITE_SIZE, WRITE_TIMEOUT);