Commit 2f649c9a authored by bencefr's avatar bencefr
Browse files

Fixed serialization transport to access queue in a safe manner

parent 3fcdc514
...@@ -160,12 +160,15 @@ uint32_t SerializationTransport::send(uint8_t *cmdBuffer, uint32_t cmdLength, ui ...@@ -160,12 +160,15 @@ uint32_t SerializationTransport::send(uint8_t *cmdBuffer, uint32_t cmdLength, ui
// Event Thread // Event Thread
void SerializationTransport::eventHandlingRunner() void SerializationTransport::eventHandlingRunner()
{ {
while (runEventThread) { do {
std::unique_lock<std::mutex> eventLock(eventMutex);
eventWaitCondition.wait(eventLock);
while (!eventQueue.empty()) while (!eventQueue.empty())
{ {
eventData_t eventData = eventQueue.front(); eventData_t eventData = eventQueue.front();
eventQueue.pop(); eventQueue.pop();
eventLock.unlock();
// Allocate memory to store decoded event including an unknown quantity of padding // Allocate memory to store decoded event including an unknown quantity of padding
// Set security context // Set security context
...@@ -188,22 +191,10 @@ void SerializationTransport::eventHandlingRunner() ...@@ -188,22 +191,10 @@ void SerializationTransport::eventHandlingRunner()
} }
free(eventData.data); free(eventData.data);
}
std::unique_lock<std::mutex> eventLock(eventMutex);
if (!runEventThread) eventLock.lock();
{
break;
}
if (!eventQueue.empty())
{
continue;
}
eventWaitCondition.wait(eventLock);
} }
} while (runEventThread);
} }
// Read Thread // Read Thread
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment