From 5fd3539cfd944bb8f7cd2d7ec828dd963aa6505d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 24 Apr 2015 11:01:17 +0200 Subject: [PATCH] Improve safety of QTestLib watchdog Reduce the side-effects of QThread start-up happening concurrently while test functions begin to execute by terminating the WatchDog constructor only when the thread itself is up and running. Change-Id: I21ee44206d789a7ecb5a220ee4729572548c0277 Reviewed-by: Lars Knoll --- src/testlib/qtestcase.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 41e0b70d21f..6799ae10877 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2046,8 +2046,10 @@ class WatchDog : public QThread public: WatchDog() { + QMutexLocker locker(&mutex); timeout.store(-1); start(); + waitCondition.wait(&mutex); } ~WatchDog() { { @@ -2072,6 +2074,7 @@ public: void run() { QMutexLocker locker(&mutex); + waitCondition.wakeAll(); while (1) { int t = timeout.load(); if (!t)