diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-09-13 10:29:49 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-09-17 10:33:05 +0000 |
commit | e0cad1aab53119a0e47467f2236f019ce8d6da2a (patch) | |
tree | 59fb834b58ff86626e4ef47668fe8579cf3cfd87 /src/widgets/widgets/qmenubar.cpp | |
parent | 35cdcddd605d8823b7b57129e8d7279133a3ca89 (diff) |
QTestLib: modernize and stream-line WatchDog
... by porting from (QWaitCondition,QMutex) to std::{condition_variable,
mutex} and making the code more accessible by introducing explicit
states.
This patch was originally starting out to just replace QWaitCondition
with std::condition_variable, which is faster and more compact, and
the patch still does that, too. The focus, however, has shifted
towards improving the accessibility of the code, in particular its
states and the transitions between them.
Due to the way QWaitCondition prevents spurious wakeups, this code
could use its QWaitCondition as a semaphore, e.g. where it was calling
wait() in the ctor to be released only when the thread it started has
entered run(). That makes the code unnecessarily hard to follow.
Fix by introducing an enum Expectation which tells what the watch-dog
is currently waiting for, and unmistakably determines the state the
watch-dog is in: ThreadStart, TestFunctionStart, ... The timeout value
is now selected based on the Expectation value, so the timeout is no
longer serving as the implicit state, either.
Also port the defaultTimeout() function to return a
std::chrono::milliseconds directly. Elsewhere in Qt, we guard against
lack of <chrono>, so this unguarded use will also serve as a guide to
see whether all supported platforms now, eight Qt releases after we
formally require C++11 for Qt usage, provide it. Without <chrono>,
there's no timed waiting in the standard library.
Change-Id: If97b601c4090a2a2926fa58c903cfe3ec2656324
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmenubar.cpp')
0 files changed, 0 insertions, 0 deletions