Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
Tasking Namespace Reference

\inmodule TaskingSolution More...

Classes

class  Barrier
 
class  BarrierTaskAdapter
 
class  ConcurrentCall
 
class  ConcurrentCallTaskAdapter
 
class  ContainerNode
 
class  CustomTask
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  ExecutableItem
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  ExecutionContextActivator
 
class  Forever
 
class  Group
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  GroupItem
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  Guard
 
class  GuardLocker
 
class  Loop
 
class  LoopData
 
class  LoopForever
 
class  LoopList
 
class  LoopRepeat
 
class  LoopThreadData
 
class  LoopUntil
 
class  NetworkQuery
 
class  NetworkQueryTaskAdapter
 
class  RuntimeContainer
 
class  RuntimeIteration
 
class  RuntimeTask
 
class  SharedBarrier
 
class  Storage
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  StorageBase
 
class  StorageData
 
class  StorageThreadData
 
class  Sync
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  TaskAdapter
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  TaskInterface
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  TaskNode
 
class  TaskTree
 \inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
 
class  TaskTreePrivate
 
class  TaskTreeRunner
 
class  TaskTreeTaskAdapter
 
class  TimeoutTaskAdapter
 
struct  TimerData
 
struct  TimerThreadData
 

Typedefs

using BarrierTask = CustomTask<BarrierTaskAdapter>
 
template<int Limit = 1>
using MultiBarrier = Storage<SharedBarrier<Limit>>
 
using SingleBarrier = MultiBarrier<1>
 
template<typename T >
using ConcurrentCallTask = CustomTask<ConcurrentCallTaskAdapter<T>>
 
using NetworkQueryTask = CustomTask<NetworkQueryTaskAdapter>
 
using StoragePtr = void *
 
using TimeoutCallback = std::function<void()>
 
using TaskTreeTask = CustomTask<TaskTreeTaskAdapter>
 
using TimeoutTask = CustomTask<TimeoutTaskAdapter>
 

Enumerations

enum class  NetworkOperation { Get , Put , Post , Delete }
 
enum class  WorkflowPolicy {
  StopOnError , ContinueOnError , StopOnSuccess , ContinueOnSuccess ,
  StopOnSuccessOrError , FinishAllAndSuccess , FinishAllAndError
}
 
enum class  SetupResult { Continue , StopWithSuccess , StopWithError }
 
enum class  DoneResult { Success , Error }
 
enum class  DoneWith { Success , Error , Cancel }
 
enum class  CallDoneIf { SuccessOrError , Success , Error }
 

Functions

template<int Limit>
GroupItem waitForBarrierTask (const MultiBarrier< Limit > &sharedBarrier)
 
GroupItem parallelLimit (int limit)
 Constructs a group's element describing the \l{Execution Mode}{execution mode}.
 
GroupItem workflowPolicy (WorkflowPolicy policy)
 Constructs a group's \l {Workflow Policy} {workflow policy} element for a given policy.
 
static TaskTreeactiveTaskTree ()
 
DoneResult toDoneResult (bool success)
 
static SetupResult toSetupResult (bool success)
 
static DoneResult toDoneResult (DoneWith doneWith)
 
static DoneWith toDoneWith (DoneResult result)
 
static QString currentTime ()
 
static QString logHeader (const QString &logName)
 
static bool initialSuccessBit (WorkflowPolicy workflowPolicy)
 
static bool isProgressive (RuntimeContainer *container)
 
static std::vector< TaskNodecreateChildren (TaskTreePrivate *taskTreePrivate, const QList< GroupItem > &children)
 
static bool shouldCall (CallDoneIf callDoneIf, DoneWith result)
 
static void removeTimerId (int timerId)
 
static void handleTimeout (int timerId)
 
static int scheduleTimeout (milliseconds timeout, QObject *context, const TimeoutCallback &callback)
 
template<typename Handler >
static GroupItem onGroupSetup (Handler &&handler)
 \typealias GroupItem::GroupSetupHandler
 
template<typename Handler >
static GroupItem onGroupDone (Handler &&handler, CallDoneIf callDoneIf=CallDoneIf::SuccessOrError)
 Constructs a group's element holding the group done handler.
 

Variables

const GroupItem nullItem = GroupItem({})
 
const GroupItem sequential = parallelLimit(1)
 
const GroupItem parallel = parallelLimit(0)
 
const GroupItem parallelIdealThreadCountLimit = parallelLimit(qMax(QThread::idealThreadCount() - 1, 1))
 
const GroupItem stopOnError = workflowPolicy(WorkflowPolicy::StopOnError)
 
const GroupItem continueOnError = workflowPolicy(WorkflowPolicy::ContinueOnError)
 
const GroupItem stopOnSuccess = workflowPolicy(WorkflowPolicy::StopOnSuccess)
 
const GroupItem continueOnSuccess = workflowPolicy(WorkflowPolicy::ContinueOnSuccess)
 
const GroupItem stopOnSuccessOrError = workflowPolicy(WorkflowPolicy::StopOnSuccessOrError)
 
const GroupItem finishAllAndSuccess = workflowPolicy(WorkflowPolicy::FinishAllAndSuccess)
 
const GroupItem finishAllAndError = workflowPolicy(WorkflowPolicy::FinishAllAndError)
 
static thread_local QList< TaskTree * > s_activeTaskTrees = {}
 
constexpr QLatin1StringView s_activeStorageWarning
 
static thread_local TimerThreadData s_threadTimerData = {}
 

Detailed Description

\inmodule TaskingSolution

The Tasking namespace encloses all classes and global functions of the Tasking solution.

Typedef Documentation

◆ BarrierTask

Definition at line 59 of file barrier.h.

◆ ConcurrentCallTask

Definition at line 113 of file concurrentcall.h.

◆ MultiBarrier

template<int Limit = 1>
using Tasking::MultiBarrier = Storage<SharedBarrier<Limit>>

Definition at line 77 of file barrier.h.

◆ NetworkQueryTask

◆ SingleBarrier

Definition at line 82 of file barrier.h.

◆ StoragePtr

Definition at line 1293 of file tasktree.cpp.

◆ TaskTreeTask

Definition at line 635 of file tasktree.h.

◆ TimeoutCallback

using Tasking::TimeoutCallback = std::function<void()>

Definition at line 3295 of file tasktree.cpp.

◆ TimeoutTask

Definition at line 636 of file tasktree.h.

Enumeration Type Documentation

◆ CallDoneIf

enum class Tasking::CallDoneIf
strong
Enumerator
SuccessOrError 
Success 
Error 

Definition at line 81 of file tasktree.h.

◆ DoneResult

enum class Tasking::DoneResult
strong
Enumerator
Success 
Error 

Definition at line 66 of file tasktree.h.

◆ DoneWith

enum class Tasking::DoneWith
strong
Enumerator
Success 
Error 
Cancel 

Definition at line 73 of file tasktree.h.

◆ NetworkOperation

enum class Tasking::NetworkOperation
strong
Enumerator
Get 
Put 
Post 
Delete 

Definition at line 37 of file networkquery.h.

◆ SetupResult

enum class Tasking::SetupResult
strong
Enumerator
Continue 
StopWithSuccess 
StopWithError 

Definition at line 58 of file tasktree.h.

◆ WorkflowPolicy

enum class Tasking::WorkflowPolicy
strong
Enumerator
StopOnError 
ContinueOnError 
StopOnSuccess 
ContinueOnSuccess 
StopOnSuccessOrError 
FinishAllAndSuccess 
FinishAllAndError 

Definition at line 46 of file tasktree.h.

Function Documentation

◆ activeTaskTree()

static TaskTree * Tasking::activeTaskTree ( )
static

Definition at line 1199 of file tasktree.cpp.

References QT_ASSERT, and s_activeTaskTrees.

Referenced by Tasking::StorageThreadData::activeStorage(), Tasking::StorageThreadData::pushStorage(), and Tasking::ExecutableItem::withLog().

+ Here is the caller graph for this function:

◆ createChildren()

static std::vector< TaskNode > Tasking::createChildren ( TaskTreePrivate * taskTreePrivate,
const QList< GroupItem > & children )
static

Definition at line 1896 of file tasktree.cpp.

References child.

◆ currentTime()

static QString Tasking::currentTime ( )
static

Definition at line 1458 of file tasktree.cpp.

References QTime::currentTime(), and Qt::ISODateWithMs.

Referenced by logHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleTimeout()

static void Tasking::handleTimeout ( int timerId)
static

Definition at line 3333 of file tasktree.cpp.

References deadline, it, QT_CHECK, and s_threadTimerData.

Referenced by scheduleTimeout().

+ Here is the caller graph for this function:

◆ initialSuccessBit()

static bool Tasking::initialSuccessBit ( WorkflowPolicy workflowPolicy)
static

Definition at line 1673 of file tasktree.cpp.

References ContinueOnError, ContinueOnSuccess, FinishAllAndError, FinishAllAndSuccess, QT_CHECK, StopOnError, StopOnSuccess, StopOnSuccessOrError, and workflowPolicy().

+ Here is the call graph for this function:

◆ isProgressive()

static bool Tasking::isProgressive ( RuntimeContainer * container)
static

Definition at line 1775 of file tasktree.cpp.

References Tasking::RuntimeIteration::m_isProgressive, Tasking::RuntimeTask::m_parentIteration, and Tasking::RuntimeContainer::m_parentTask.

Referenced by Tasking::TaskTreePrivate::start().

+ Here is the caller graph for this function:

◆ logHeader()

static QString Tasking::logHeader ( const QString & logName)
static

Definition at line 1460 of file tasktree.cpp.

References currentTime(), and QString::fromLatin1().

Referenced by Tasking::ExecutableItem::withLog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onGroupDone()

template<typename Handler >
template< typename Handler > GroupItem Tasking::onGroupDone ( Handler && handler,
CallDoneIf callDoneIf = CallDoneIf::SuccessOrError )
static

Constructs a group's element holding the group done handler.

By default, the handler is invoked whenever the group finishes. Pass a non-default value for the callDoneIf argument when you want the handler to be called only on a successful or failed execution. Depending on the group's workflow policy, this handler may also be called when the running group is canceled (e.g. when stopOnError element was used).

The passed handler is of the std::function<DoneResult(DoneWith)> type. Optionally, each of the return DoneResult type or the argument DoneWith type may be omitted (that is, its return type may be void). For more information on a possible handler type, refer to \l {GroupItem::GroupDoneHandler}.

When the handler is invoked, all of the group's child tasks are already finished.

If a group contains the Storage elements, the handler is invoked before the storages are destructed, so that the handler may still perform a last read of the active storages' data.

See also
GroupItem::GroupDoneHandler, onGroupSetup()

Definition at line 393 of file tasktree.h.

References onGroupDone().

Referenced by onGroupDone(), Assets::Downloader::AssetDownloader::start(), and Tasking::ExecutableItem::withLog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onGroupSetup()

template<typename Handler >
template< typename Handler > GroupItem Tasking::onGroupSetup ( Handler && handler)
static

\typealias GroupItem::GroupSetupHandler

Type alias for std::function<SetupResult()>.

The GroupSetupHandler is an argument of the onGroupSetup() element. Any function with the above signature, when passed as a group setup handler, will be called by the running task tree when the group execution starts.

The return value of the handler instructs the running group on how to proceed after the handler's invocation is finished. The default return value of SetupResult::Continue instructs the group to continue running, that is, to start executing its child tasks. The return value of SetupResult::StopWithSuccess or SetupResult::StopWithError instructs the group to skip the child tasks' execution and finish immediately with success or an error, respectively.

When the return type is either SetupResult::StopWithSuccess or SetupResult::StopWithError, the group's done handler (if provided) is called synchronously immediately afterwards.

Note
Even if the group setup handler returns StopWithSuccess or StopWithError, the group's done handler is invoked. This behavior differs from that of task done handler and might change in the future.

The onGroupSetup() element accepts also functions in the shortened form of std::function<void()>, that is, the return value is void. In this case, it's assumed that the return value is SetupResult::Continue.

See also
onGroupSetup(), GroupDoneHandler, CustomTask::TaskSetupHandler

\typealias GroupItem::GroupDoneHandler

Type alias for std::function<DoneResult(DoneWith)>.

The GroupDoneHandler is an argument of the onGroupDone() element. Any function with the above signature, when passed as a group done handler, will be called by the running task tree when the group execution ends.

The DoneWith argument is optional and your done handler may omit it. When provided, it holds the info about the final result of a group that will be reported to its parent.

The returned DoneResult value is optional and your handler may return void instead. In this case, the final result of the group will be equal to the value indicated by the DoneWith argument. When the handler returns the DoneResult value, the group's final result may be tweaked inside the done handler's body by the returned value.

See also
onGroupDone(), GroupSetupHandler, CustomTask::TaskDoneHandler

Constructs a group's element holding the group setup handler. The handler is invoked whenever the group starts.

The passed handler is either of the std::function<SetupResult()> or the std::function<void()> type. For more information on a possible handler type, refer to \l {GroupItem::GroupSetupHandler}.

When the handler is invoked, none of the group's child tasks are running yet.

If a group contains the Storage elements, the handler is invoked after the storages are constructed, so that the handler may already perform some initial modifications to the active storages.

See also
GroupItem::GroupSetupHandler, onGroupDone()

Definition at line 387 of file tasktree.h.

References onGroupSetup().

Referenced by Tasking::Sync::Sync(), onGroupSetup(), Assets::Downloader::AssetDownloader::start(), and Tasking::ExecutableItem::withLog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parallelLimit()

TASKING_EXPORT GroupItem Tasking::parallelLimit ( int limit)

Constructs a group's element describing the \l{Execution Mode}{execution mode}.

The execution mode element in a Group specifies how the direct child tasks of the Group are started.

For convenience, when appropriate, the \l sequential or \l parallel global elements may be used instead.

The limit defines the maximum number of direct child tasks running in parallel:

\list

  • When limit equals to 0, there is no limit, and all direct child tasks are started together, in the oder in which they appear in a group. This means the fully parallel execution, and the \l parallel element may be used instead.
  • When limit equals to 1, it means that only one child task may run at the time. This means the sequential execution, and the \l sequential element may be used instead. In this case, child tasks run in chain, so the next child task starts after the previous child task has finished.
  • When other positive number is passed as limit, the group's child tasks run in parallel, but with a limited number of tasks running simultanously. The limit defines the maximum number of tasks running in parallel in a group. When the group is started, the first batch of tasks is started (the number of tasks in a batch equals to the passed limit, at most), while the others are kept waiting. When any running task finishes, the group starts the next remaining one, so that the limit of simultaneously running tasks inside a group isn't exceeded. This repeats on every child task's finish until all child tasks are started. This enables you to limit the maximum number of tasks that run simultaneously, for example if running too many processes might block the machine for a long time. \endlist

In all execution modes, a group starts tasks in the oder in which they appear.

If a child of a group is also a group, the child group runs its tasks according to its own execution mode.

See also
sequential, parallel

Definition at line 1162 of file tasktree.cpp.

References Tasking::Group::parallelLimit(), and qMax().

+ Here is the call graph for this function:

◆ removeTimerId()

static void Tasking::removeTimerId ( int timerId)
static

Definition at line 3317 of file tasktree.cpp.

References deadline, it, QT_ASSERT, qWarning, and s_threadTimerData.

Referenced by Tasking::TimeoutTaskAdapter::~TimeoutTaskAdapter().

+ Here is the caller graph for this function:

◆ scheduleTimeout()

static int Tasking::scheduleTimeout ( milliseconds timeout,
QObject * context,
const TimeoutCallback & callback )
static

Definition at line 3372 of file tasktree.cpp.

References deadline, handleTimeout(), s_threadTimerData, and QTimer::singleShot.

Referenced by Tasking::TimeoutTaskAdapter::start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shouldCall()

static bool Tasking::shouldCall ( CallDoneIf callDoneIf,
DoneWith result )
static

Definition at line 2106 of file tasktree.cpp.

References Error, and Success.

Referenced by Tasking::TaskTreePrivate::invokeDoneHandler(), and Tasking::TaskTreePrivate::invokeDoneHandler().

+ Here is the caller graph for this function:

◆ toDoneResult() [1/2]

TASKING_EXPORT DoneResult Tasking::toDoneResult ( bool success)

Definition at line 1205 of file tasktree.cpp.

References Error, and Success.

Referenced by Tasking::TaskTreeTaskAdapter::TaskTreeTaskAdapter(), Tasking::TaskTreePrivate::invokeDoneHandler(), and Tasking::TaskTreePrivate::invokeDoneHandler().

+ Here is the caller graph for this function:

◆ toDoneResult() [2/2]

static DoneResult Tasking::toDoneResult ( DoneWith doneWith)
static

Definition at line 1215 of file tasktree.cpp.

References Error, and Success.

◆ toDoneWith()

static DoneWith Tasking::toDoneWith ( DoneResult result)
static

Definition at line 1220 of file tasktree.cpp.

References Error, and Success.

◆ toSetupResult()

static SetupResult Tasking::toSetupResult ( bool success)
static

Definition at line 1210 of file tasktree.cpp.

References StopWithError, and StopWithSuccess.

Referenced by Tasking::TaskTreePrivate::childDone(), Tasking::TaskTreePrivate::start(), and Tasking::TaskTreePrivate::startChildren().

+ Here is the caller graph for this function:

◆ waitForBarrierTask()

template<int Limit>
GroupItem Tasking::waitForBarrierTask ( const MultiBarrier< Limit > & sharedBarrier)

Definition at line 85 of file barrier.h.

References QObject::connect(), Continue, Tasking::Barrier::done(), qWarning, Tasking::Barrier::result(), StopWithError, Tasking::Barrier::stopWithResult(), StopWithSuccess, and Success.

+ Here is the call graph for this function:

◆ workflowPolicy()

TASKING_EXPORT GroupItem Tasking::workflowPolicy ( WorkflowPolicy policy)

Constructs a group's \l {Workflow Policy} {workflow policy} element for a given policy.

For convenience, global elements may be used instead.

See also
stopOnError, continueOnError, stopOnSuccess, continueOnSuccess, stopOnSuccessOrError, finishAllAndSuccess, finishAllAndError, WorkflowPolicy

Definition at line 1175 of file tasktree.cpp.

References policy, and Tasking::Group::workflowPolicy().

Referenced by Tasking::TaskTreePrivate::childDone(), and initialSuccessBit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ continueOnError

Definition at line 1187 of file tasktree.cpp.

◆ continueOnSuccess

Definition at line 1189 of file tasktree.cpp.

◆ finishAllAndError

Definition at line 1192 of file tasktree.cpp.

Referenced by Tasking::ExecutableItem::withTimeout().

◆ finishAllAndSuccess

Definition at line 1191 of file tasktree.cpp.

◆ nullItem

TASKING_EXPORT const GroupItem Tasking::nullItem = GroupItem({})

Definition at line 1180 of file tasktree.cpp.

◆ parallel

TASKING_EXPORT const GroupItem Tasking::parallel = parallelLimit(0)

Definition at line 1183 of file tasktree.cpp.

Referenced by Tasking::ExecutableItem::withTimeout().

◆ parallelIdealThreadCountLimit

TASKING_EXPORT const GroupItem Tasking::parallelIdealThreadCountLimit = parallelLimit(qMax(QThread::idealThreadCount() - 1, 1))

Definition at line 1184 of file tasktree.cpp.

Referenced by Assets::Downloader::AssetDownloader::start().

◆ s_activeStorageWarning

constexpr QLatin1StringView Tasking::s_activeStorageWarning
constexpr
Initial value:
=
"The referenced storage is not reachable in the running tree. "
"A nullptr will be returned which might lead to a crash in the calling code. "
"It is possible that no storage was added to the tree, "
"or the storage is not reachable from where it is referenced."_L1

Definition at line 1295 of file tasktree.cpp.

Referenced by Tasking::StorageThreadData::activeStorage().

◆ s_activeTaskTrees

thread_local QList<TaskTree *> Tasking::s_activeTaskTrees = {}
static

◆ s_threadTimerData

thread_local TimerThreadData Tasking::s_threadTimerData = {}
static

Definition at line 3315 of file tasktree.cpp.

Referenced by handleTimeout(), removeTimerId(), and scheduleTimeout().

◆ sequential

TASKING_EXPORT const GroupItem Tasking::sequential = parallelLimit(1)

Definition at line 1182 of file tasktree.cpp.

◆ stopOnError

Definition at line 1186 of file tasktree.cpp.

◆ stopOnSuccess

Definition at line 1188 of file tasktree.cpp.

◆ stopOnSuccessOrError

Definition at line 1190 of file tasktree.cpp.

Referenced by Tasking::ExecutableItem::withTimeout().