diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-10-18 17:13:53 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-10-21 23:20:35 +0200 |
commit | a9bf6e652aa99784343c94b0181c9443205e2a82 (patch) | |
tree | 6ff4a5c358f1f1bd0523a66733c75c31ca4a3cc5 /src/qml/qml/qqmlincubator.cpp | |
parent | fecfa43cfac329a5b50663cd04bb74bf5a63ca6f (diff) |
QQmlIncubationController::incubateWhile: port to atomic<bool>
"volatile bool" does not guarantee synchronization, and as such,
the documentation (and the intended use case, having another
thread stopping incubation) are wrong. Add a different overload
that takes a std::atomic<bool> as a replacement.
Change-Id: I05e2d608385d075ef67989839d6c0a634da7a64b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlincubator.cpp')
-rw-r--r-- | src/qml/qml/qqmlincubator.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp index f0ef5360b0..d9c965d3ea 100644 --- a/src/qml/qml/qqmlincubator.cpp +++ b/src/qml/qml/qqmlincubator.cpp @@ -410,14 +410,39 @@ void QQmlIncubationController::incubateFor(int msecs) } while (d && d->incubatorCount != 0 && !i.shouldInterrupt()); } +#if QT_DEPRECATED_SINCE(5, 15) /*! -Incubate objects while the bool pointed to by \a flag is true, or until there are no -more objects to incubate, or up to \a msecs if \a msecs is not zero. +\obsolete + +\warning Do not use this function. +Use the overload taking a \c{std::atomic<bool>} instead. +*/ +void QQmlIncubationController::incubateWhile(volatile bool *flag, int msecs) +{ + if (!d || !d->incubatorCount) + return; + + QQmlInstantiationInterrupt i(flag, msecs * 1000000); + i.reset(); + do { + static_cast<QQmlIncubatorPrivate*>(d->incubatorList.first())->incubate(i); + } while (d && d->incubatorCount != 0 && !i.shouldInterrupt()); +} +#endif + +/*! +\since 5.15 + +Incubate objects while the atomic bool pointed to by \a flag is true, +or until there are no more objects to incubate, or up to \a msecs if \a +msecs is not zero. Generally this method is used in conjunction with a thread or a UNIX signal that sets the bool pointed to by \a flag to false when it wants incubation to be interrupted. + +\note \a flag is read using acquire memory ordering. */ -void QQmlIncubationController::incubateWhile(volatile bool *flag, int msecs) +void QQmlIncubationController::incubateWhile(std::atomic<bool> *flag, int msecs) { if (!d || !d->incubatorCount) return; |