diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-19 03:10:09 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-19 03:10:09 +0100 |
commit | 58385e4a48ff85fa847b4264d3f5216f62af24c1 (patch) | |
tree | aa1624281830acfc4b6aa14d6e61ed16b2f50450 /async/src/future.h | |
parent | d417f01e2eebeedfaae76b40667372bd0fb21fea (diff) | |
download | sink-58385e4a48ff85fa847b4264d3f5216f62af24c1.tar.gz sink-58385e4a48ff85fa847b4264d3f5216f62af24c1.zip |
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.
Diffstat (limited to 'async/src/future.h')
-rw-r--r-- | async/src/future.h | 13 |
1 files changed, 9 insertions, 4 deletions
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: | |||
35 | virtual ~FutureBase(); | 35 | virtual ~FutureBase(); |
36 | 36 | ||
37 | virtual void setFinished() = 0; | 37 | virtual void setFinished() = 0; |
38 | bool isFinished() const; | 38 | virtual bool isFinished() const = 0; |
39 | 39 | ||
40 | protected: | 40 | protected: |
41 | FutureBase(); | 41 | FutureBase(); |
42 | FutureBase(const FutureBase &other); | 42 | FutureBase(const FutureBase &other); |
43 | |||
44 | bool mFinished; | ||
45 | }; | 43 | }; |
46 | 44 | ||
47 | template<typename T> | 45 | template<typename T> |
@@ -58,7 +56,7 @@ class FutureGeneric : public FutureBase | |||
58 | public: | 56 | public: |
59 | void setFinished() | 57 | void setFinished() |
60 | { | 58 | { |
61 | mFinished = true; | 59 | d->finished = true; |
62 | for (auto watcher : d->watchers) { | 60 | for (auto watcher : d->watchers) { |
63 | if (watcher) { | 61 | if (watcher) { |
64 | watcher->futureReadyCallback(); | 62 | watcher->futureReadyCallback(); |
@@ -66,6 +64,11 @@ public: | |||
66 | } | 64 | } |
67 | } | 65 | } |
68 | 66 | ||
67 | bool isFinished() const | ||
68 | { | ||
69 | return d->finished; | ||
70 | } | ||
71 | |||
69 | void waitForFinished() | 72 | void waitForFinished() |
70 | { | 73 | { |
71 | if (isFinished()) { | 74 | if (isFinished()) { |
@@ -93,10 +96,12 @@ protected: | |||
93 | class Private : public QSharedData | 96 | class Private : public QSharedData |
94 | { | 97 | { |
95 | public: | 98 | public: |
99 | Private() : QSharedData(), finished(false) {} | ||
96 | typename std::conditional<std::is_void<T>::value, int /* dummy */, T>::type | 100 | typename std::conditional<std::is_void<T>::value, int /* dummy */, T>::type |
97 | value; | 101 | value; |
98 | 102 | ||
99 | QVector<QPointer<FutureWatcher<T>>> watchers; | 103 | QVector<QPointer<FutureWatcher<T>>> watchers; |
104 | bool finished; | ||
100 | }; | 105 | }; |
101 | 106 | ||
102 | QExplicitlySharedDataPointer<Private> d; | 107 | QExplicitlySharedDataPointer<Private> d; |