From 8184ff6bfb57284eac733bc4f4cefa8a998b61de Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 29 Jul 2016 15:46:25 +0200 Subject: [PATCH] Client tests: Unlock mutex while processing compositor commands Only lock the client autotest compositor mutex when necessary. This allows compositor commands to be queued while a command is being processed. Change-Id: Ib2ca6b4942f57f56f56a055cbe6ce6d876695529 Reviewed-by: Paul Olav Tvete --- tests/auto/wayland/mockcompositor.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/auto/wayland/mockcompositor.cpp b/tests/auto/wayland/mockcompositor.cpp index 68245226286..7eb683191ec 100644 --- a/tests/auto/wayland/mockcompositor.cpp +++ b/tests/auto/wayland/mockcompositor.cpp @@ -185,9 +185,16 @@ void MockCompositor::processCommand(const Command &command) void MockCompositor::dispatchCommands() { - foreach (const Command &command, m_commandQueue) + lock(); + int count = m_commandQueue.length(); + unlock(); + + for (int i = 0; i < count; ++i) { + lock(); + const Command command = m_commandQueue.takeFirst(); + unlock(); command.callback(command.target, command.parameters); - m_commandQueue.clear(); + } } void *MockCompositor::run(void *data) @@ -205,8 +212,11 @@ void *MockCompositor::run(void *data) } while (controller->m_alive) { - QMutexLocker locker(&controller->m_mutex); - controller->m_waitCondition.wait(&controller->m_mutex); + { + QMutexLocker locker(&controller->m_mutex); + if (controller->m_commandQueue.isEmpty()) + controller->m_waitCondition.wait(&controller->m_mutex); + } controller->dispatchCommands(); compositor.dispatchEvents(20); }