Tidy up qtestcase.cpp's WatchDog

It now uses QtPrivate::condition_variable, it pulls in the correct
header for that, so #include <condition_variable> is no longer needed.
Separate opening braces of function bodies onto next line.

Change-Id: I08f721c4d52756932bb9409e34e51dcbb3eda104
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Edward Welbourne 2021-07-14 14:19:33 +02:00 committed by Marc Mutz
parent 19f522c74a
commit 8ffede6543

View File

@ -85,7 +85,6 @@
#include <cmath> #include <cmath>
#include <numeric> #include <numeric>
#include <algorithm> #include <algorithm>
#include <condition_variable>
#include <mutex> #include <mutex>
#include <chrono> #include <chrono>
@ -1023,7 +1022,8 @@ class WatchDog : public QThread
ThreadEnd, ThreadEnd,
}; };
bool waitFor(std::unique_lock<QtPrivate::mutex> &m, Expectation e) { bool waitFor(std::unique_lock<QtPrivate::mutex> &m, Expectation e)
{
auto expectationChanged = [this, e] { return expecting.load(std::memory_order_relaxed) != e; }; auto expectationChanged = [this, e] { return expecting.load(std::memory_order_relaxed) != e; };
switch (e) { switch (e) {
case TestFunctionEnd: case TestFunctionEnd:
@ -1047,7 +1047,9 @@ public:
start(); start();
waitFor(locker, ThreadStart); waitFor(locker, ThreadStart);
} }
~WatchDog() {
~WatchDog()
{
{ {
const auto locker = qt_scoped_lock(mutex); const auto locker = qt_scoped_lock(mutex);
expecting.store(ThreadEnd, std::memory_order_relaxed); expecting.store(ThreadEnd, std::memory_order_relaxed);
@ -1056,19 +1058,22 @@ public:
wait(); wait();
} }
void beginTest() { void beginTest()
{
const auto locker = qt_scoped_lock(mutex); const auto locker = qt_scoped_lock(mutex);
expecting.store(TestFunctionEnd, std::memory_order_relaxed); expecting.store(TestFunctionEnd, std::memory_order_relaxed);
waitCondition.notify_all(); waitCondition.notify_all();
} }
void testFinished() { void testFinished()
{
const auto locker = qt_scoped_lock(mutex); const auto locker = qt_scoped_lock(mutex);
expecting.store(TestFunctionStart, std::memory_order_relaxed); expecting.store(TestFunctionStart, std::memory_order_relaxed);
waitCondition.notify_all(); waitCondition.notify_all();
} }
void run() override { void run() override
{
auto locker = qt_unique_lock(mutex); auto locker = qt_unique_lock(mutex);
expecting.store(TestFunctionStart, std::memory_order_release); expecting.store(TestFunctionStart, std::memory_order_release);
waitCondition.notify_all(); waitCondition.notify_all();