1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02: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,29 +227,31 @@ 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());
while (size <= 0) {
// wait on new data to write condition, the timeout
// enable the thread to shutdown properly
m_newDataToWrite.wait(&m_writeBufMtx, 200);
if (!m_running) {
return;
{
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
m_newDataToWrite.wait(&m_writeBufMtx, 200);
if (!m_running) {
return;
}
size = m_writeBuffer.size();
}
size = m_writeBuffer.size();
// NOTE: data size is limited to 2 bytes less than the
// usb packet size (64 bytes for interrupt) to make room
// for the reportID and valid data length
size = qMin(WRITE_SIZE - 2, m_writeBuffer.size());
memcpy(&buffer[2], m_writeBuffer.constData(), size);
buffer[1] = size; // valid data length
buffer[0] = 2; // reportID
}
// NOTE: data size is limited to 2 bytes less than the
// usb packet size (64 bytes for interrupt) to make room
// for the reportID and valid data length
size = qMin(WRITE_SIZE - 2, m_writeBuffer.size());
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);