Plasma Engine  2.0
Loading...
Searching...
No Matches
Task.h
1#pragma once
2
3#include <Foundation/Strings/String.h>
4#include <Foundation/Threading/AtomicInteger.h>
5#include <Foundation/Threading/Implementation/TaskSystemDeclarations.h>
6#include <Foundation/Types/RefCounted.h>
7
9class PL_FOUNDATION_DLL plTask : public plRefCounted
10{
11 PL_DISALLOW_COPY_AND_ASSIGN(plTask);
12
13public:
14 plTask();
15 virtual ~plTask();
16
28 void ConfigureTask(const char* szTaskName, plTaskNesting nestingMode, plOnTaskFinishedCallback callback = plOnTaskFinishedCallback()); // [tested]
29
42 void SetMultiplicity(plUInt32 uiMultiplicity); // [tested]
43
45 plUInt32 GetMultiplicity() const { return m_uiMultiplicity; } // [tested]
46
55 bool IsTaskFinished() const { return m_iRemainingRuns == 0; } // [tested]
56
58 bool HasBeenCanceled() const { return m_bCancelExecution; } // [tested]
59
60protected:
65 virtual void Execute() {} // [tested]
66
76 virtual void ExecuteWithMultiplicity(plUInt32 uiInvocation) const {} // [tested]
77
78private:
79 // The task system and its worker threads implement most of the functionality of the task handling.
80 // Therefore they are allowed to modify all this internal state.
81 friend class plTaskSystem;
82
83 void Reset();
84
86 void Run(plUInt32 uiInvocation);
87
89 plAtomicInteger32 m_iRemainingRuns;
90
92 bool m_bCancelExecution = false;
93
95 bool m_bTaskIsScheduled = false;
96
98 bool m_bUsesMultiplicity = false;
99
100 plUInt32 m_uiMultiplicity = 0;
101
103 plTaskNesting m_NestingMode = plTaskNesting::Maybe;
104
106 plOnTaskFinishedCallback m_OnTaskFinished;
107
109 plTaskGroupID m_BelongsToGroup;
110
111 plString m_sTaskName;
112};
Base class for reference counted objects.
Definition RefCounted.h:52
Given out by plTaskSystem::CreateTaskGroup to identify a task group.
Definition TaskSystemDeclarations.h:103
Base class for custom tasks.
Definition Task.h:10
bool HasBeenCanceled() const
Can be used inside an overridden 'Execute' function to terminate execution prematurely.
Definition Task.h:58
virtual void ExecuteWithMultiplicity(plUInt32 uiInvocation) const
Override this to implement the task's supposed functionality.
Definition Task.h:76
virtual void Execute()
Override this to implement the task's supposed functionality.
Definition Task.h:65
bool IsTaskFinished() const
Returns whether the task has been finished. This includes being canceled.
Definition Task.h:55
plUInt32 GetMultiplicity() const
Definition Task.h:45
This system allows to automatically distribute tasks onto a number of worker threads.
Definition TaskSystem.h:25