diff options
| author | Ivan Solovev <ivan.solovev@qt.io> | 2025-01-28 18:34:26 +0100 |
|---|---|---|
| committer | Ivan Solovev <ivan.solovev@qt.io> | 2025-02-11 12:19:50 +0100 |
| commit | cdc71532ec2b5d29995f0f34249ebe2174b28c9c (patch) | |
| tree | 1abf9afc52d297c06877b0f41ae4231026575767 /src/corelib/thread/qfutureinterface.h | |
| parent | 3164746eb09a34818cfa874ae248d01e0c4f5d74 (diff) | |
Add QFuture::cancelChain()
This method should be used on a future returned from the long
continuation chain, if this chain needs to be canceled altogether.
To achieve it, this commit introduces a pointer to the parent data.
That pointer is set when setContinuation() is called, and cleaned
when the parent is completed and calls its runContinuation()
method. This allows the code in cancelChain() to simply move up
the chain as long as the parent pointer is valid, and cancel each
of the continuations.
The commit also moves the QFIB::cancel() implementation into
QFIBP::cancelImpl(), so that it can be reused in the new method,
and introduces an enum for cancellation options, to address the
differences in the behavior between these two methods.
Note that the approach consistently works only on the last QFuture
of the chain, because the already-executed continuations might
clear their continuation data, which makes navigating down the
chain inconsistent.
[ChangeLog][QtCore][QFuture] Added QFuture::cancelChain().
Fixes: QTBUG-130662
Change-Id: Ic0949ed30a2f54f99597e95b3951fda6bfb9a0be
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/thread/qfutureinterface.h')
| -rw-r--r-- | src/corelib/thread/qfutureinterface.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index e3d0332f6f0..3224288228c 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -127,6 +127,7 @@ public: void cancel(); void cancelAndFinish() { cancel(CancelMode::CancelAndFinish); } + void cancelChain(); void setSuspended(bool suspend); void toggleSuspended(); @@ -221,6 +222,7 @@ protected: enum class CancelMode { CancelOnly, CancelAndFinish }; void cancel(CancelMode mode); + void cancelChain(CancelMode mode); }; inline void swap(QFutureInterfaceBase &lhs, QFutureInterfaceBase &rhs) noexcept |
