NeoPZ
TPZTask.cpp
Go to the documentation of this file.
1 /*
2  * File: TPZTask.cpp
3  * Author: Thiago
4  *
5  * Created on 19 de Junho de 2018, 14:08
6  */
7 
8 #include "TPZTask.h"
9 
10 #include "TPZTaskGroup.h"
11 
12 TPZTask::TPZTask(const int priority, TPZAutoPointer<std::packaged_task<void(void)>> &task, TPZTaskGroup *taskGroup) :
13 mSystemTask(false),
14 mPriority(priority),
15 mTask(task),
16 mState(EProcessingState::CREATED),
17 mTaskGroup(taskGroup) {
18  if (taskGroup){
19  taskGroup->RegisterTask(this);
20  }
21 }
22 
23 int TPZTask::priority() const {
24  return mPriority;
25 }
26 
28  mState = EProcessingState::STARTED;
29  (*mTask)();
30  mState = EProcessingState::FINISHED;
31  if (mTaskGroup) {
32  mTaskGroup->Notify(this);
33  }
34 }
35 
37  if (mTaskGroup){
38  mTaskGroup->Notify(this);
39  }
40 }
41 
42 
44 }
TPZTask(const int priority, TPZAutoPointer< std::packaged_task< void(void)>> &task, TPZTaskGroup *taskGroup=NULL)
Definition: TPZTask.cpp:12
EProcessingState mState
Definition: TPZTask.h:39
virtual ~TPZTask()
Definition: TPZTask.cpp:43
TPZTaskGroup * mTaskGroup
Definition: TPZTask.h:41
virtual void start()
Definition: TPZTask.cpp:27
virtual void Cancel()
Definition: TPZTask.cpp:36
int mPriority
Definition: TPZTask.h:44
EProcessingState
Definition: TPZTask.h:31
void Notify(TPZTask *task)
int priority() const
Definition: TPZTask.cpp:23
void RegisterTask(TPZTask *task)
This class implements a reference counter mechanism to administer a dynamically allocated object...