diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-06-07 20:15:39 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-06-12 03:08:59 +0200 |
commit | 6460c3c33d8f880c50e2b529827437e442d05bd3 (patch) | |
tree | 329c03c69e345296c26bb0b589eab685f2246a62 /src/corelib/thread/qfutureinterface_p.h | |
parent | e0ae1af278f3cc6df6c3f66e4118585cc8384b15 (diff) |
QFuture: put the result store and the exception store in a union
QFuture doesn't need both at the same time, calling QFuture::result(s)
either returns a result or throws an exception. Store result and
exception stores in a union, to reduce the memory.
Also added a note for making the ResultStoreBase destructor non-virtual
in Qt 7.
Task-number: QTBUG-92045
Change-Id: I7f0ac03804d19cc67c1a1466c7a1365219768a14
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/thread/qfutureinterface_p.h')
-rw-r--r-- | src/corelib/thread/qfutureinterface_p.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/corelib/thread/qfutureinterface_p.h b/src/corelib/thread/qfutureinterface_p.h index 44c3a48d2a..a717a1143f 100644 --- a/src/corelib/thread/qfutureinterface_p.h +++ b/src/corelib/thread/qfutureinterface_p.h @@ -134,6 +134,7 @@ class QFutureInterfaceBasePrivate { public: QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState); + ~QFutureInterfaceBasePrivate(); // When the last QFuture<T> reference is removed, we need to make // sure that data stored in the ResultStore is cleaned out. @@ -167,9 +168,22 @@ public: QElapsedTimer progressTime; QWaitCondition waitCondition; QWaitCondition pausedWaitCondition; - // ### TODO: put m_results and m_exceptionStore into a union (see QTBUG-92045) - QtPrivate::ResultStoreBase m_results; - QtPrivate::ExceptionStore m_exceptionStore; + + union Data { + QtPrivate::ResultStoreBase m_results; + QtPrivate::ExceptionStore m_exceptionStore; + + void setException(const std::exception_ptr &e) + { + m_results.~ResultStoreBase(); + new (&m_exceptionStore) QtPrivate::ExceptionStore(); + m_exceptionStore.setException(e); + } + + ~Data() { } + }; + Data data = { QtPrivate::ResultStoreBase() }; + QString m_progressText; QRunnable *runnable = nullptr; QThreadPool *m_pool = nullptr; @@ -185,6 +199,7 @@ public: bool manualProgress = false; // only accessed from executing thread bool launchAsync = false; bool isValid = false; + bool hasException = false; inline QThreadPool *pool() const { return m_pool ? m_pool : QThreadPool::globalInstance(); } |