From 58385e4a48ff85fa847b4264d3f5216f62af24c1 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 19 Jan 2015 03:10:09 +0100 Subject: Fixed Async::Future. The future is copied an the finished boolean has to be in the shared part, otherwise the original copy never receives the updated value. --- async/src/async.h | 5 ++--- async/src/future.cpp | 7 ------- async/src/future.h | 13 +++++++++---- 3 files changed, 11 insertions(+), 14 deletions(-) (limited to 'async') diff --git a/async/src/async.h b/async/src/async.h index 171a245..8fee0bc 100644 --- a/async/src/async.h +++ b/async/src/async.h @@ -300,8 +300,7 @@ void Executor::exec() auto futureWatcher = new Async::FutureWatcher(); QObject::connect(futureWatcher, &Async::FutureWatcher::futureReady, [futureWatcher, this]() { - //FIXME mFinished is not part of the d-pointer but we copy the future below - // assert(futureWatcher->future().isFinished()); + assert(futureWatcher->future().isFinished()); futureWatcher->deleteLater(); previousFutureReady(); }); @@ -320,7 +319,7 @@ template void ThenExecutor::previousFutureReady() { if (this->mPrevFuture) { - assert(this->mPrevFuture->isFinished()); + assert(this->mPrevFuture->isFinished()); } this->mFunc(this->mPrevFuture ? this->mPrevFuture->value() : In() ..., *static_cast*>(this->mResult)); diff --git a/async/src/future.cpp b/async/src/future.cpp index 4b34514..ab02baf 100644 --- a/async/src/future.cpp +++ b/async/src/future.cpp @@ -20,12 +20,10 @@ using namespace Async; FutureBase::FutureBase() - : mFinished(false) { } FutureBase::FutureBase(const Async::FutureBase &other) - : mFinished(other.mFinished) { } @@ -33,11 +31,6 @@ FutureBase::~FutureBase() { } -bool FutureBase::isFinished() const -{ - return mFinished; -} - FutureWatcherBase::FutureWatcherBase(QObject *parent) : QObject(parent) { diff --git a/async/src/future.h b/async/src/future.h index aa8e9be..54580ad 100644 --- a/async/src/future.h +++ b/async/src/future.h @@ -35,13 +35,11 @@ public: virtual ~FutureBase(); virtual void setFinished() = 0; - bool isFinished() const; + virtual bool isFinished() const = 0; protected: FutureBase(); FutureBase(const FutureBase &other); - - bool mFinished; }; template @@ -58,7 +56,7 @@ class FutureGeneric : public FutureBase public: void setFinished() { - mFinished = true; + d->finished = true; for (auto watcher : d->watchers) { if (watcher) { watcher->futureReadyCallback(); @@ -66,6 +64,11 @@ public: } } + bool isFinished() const + { + return d->finished; + } + void waitForFinished() { if (isFinished()) { @@ -93,10 +96,12 @@ protected: class Private : public QSharedData { public: + Private() : QSharedData(), finished(false) {} typename std::conditional::value, int /* dummy */, T>::type value; QVector>> watchers; + bool finished; }; QExplicitlySharedDataPointer d; -- cgit v1.2.3