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 <numeric>
#include <algorithm>
#include <condition_variable>
#include <mutex>
#include <chrono>
@ -1023,7 +1022,8 @@ class WatchDog : public QThread
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; };
switch (e) {
case TestFunctionEnd:
@ -1047,7 +1047,9 @@ public:
start();
waitFor(locker, ThreadStart);
}
~WatchDog() {
~WatchDog()
{
{
const auto locker = qt_scoped_lock(mutex);
expecting.store(ThreadEnd, std::memory_order_relaxed);
@ -1056,19 +1058,22 @@ public:
wait();
}
void beginTest() {
void beginTest()
{
const auto locker = qt_scoped_lock(mutex);
expecting.store(TestFunctionEnd, std::memory_order_relaxed);
waitCondition.notify_all();
}
void testFinished() {
void testFinished()
{
const auto locker = qt_scoped_lock(mutex);
expecting.store(TestFunctionStart, std::memory_order_relaxed);
waitCondition.notify_all();
}
void run() override {
void run() override
{
auto locker = qt_unique_lock(mutex);
expecting.store(TestFunctionStart, std::memory_order_release);
waitCondition.notify_all();