NeoPZ
TPZTask.h
Go to the documentation of this file.
1 /*
2  * File: TPZTask.h
3  * Author: Thiago
4  *
5  * Created on 19 de Junho de 2018, 14:08
6  */
7 
8 #ifndef TPZTASK_H
9 #define TPZTASK_H
10 
11 #include <future>
12 #include <tpzautopointer.h>
13 
14 class TPZTaskGroup;
15 
17 // Object of this class will be created by the TPZThreadPool class "automatically"
18 class TPZTask {
19 public:
20 
21  TPZTask(const int priority, TPZAutoPointer<std::packaged_task<void(void)>> &task, TPZTaskGroup *taskGroup = NULL);
22  int priority() const;
23  virtual void start();
24  virtual void Cancel();
25  virtual ~TPZTask();
26 
27  friend struct TPZTaskOrdering;
28  friend class TPZThreadPool;
29 
30 protected :
36  };
37 
40 
42 private:
44  int mPriority;
45 };
46 
49 
51  if (lhs->mSystemTask) {
52  if (rhs->mSystemTask) {
53  return lhs->priority() < rhs->priority();
54  } else {
55  return false;
56  }
57  } else if (rhs->mSystemTask){
58  return true;
59  } else {
60  return lhs->priority() < rhs->priority();
61  }
62  }
63 };
64 
65 
66 #endif /* TPZTASK_H */
67 
TPZTask(const int priority, TPZAutoPointer< std::packaged_task< void(void)>> &task, TPZTaskGroup *taskGroup=NULL)
Definition: TPZTask.cpp:12
EProcessingState mState
Definition: TPZTask.h:39
Administers tasks that will be executed asynchronously.
Definition: TPZThreadPool.h:23
virtual ~TPZTask()
Definition: TPZTask.cpp:43
bool operator()(const TPZAutoPointer< TPZTask > &lhs, const TPZAutoPointer< TPZTask > &rhs)
Definition: TPZTask.h:50
TPZTaskGroup * mTaskGroup
Definition: TPZTask.h:41
virtual void start()
Definition: TPZTask.cpp:27
TPZAutoPointer< std::packaged_task< void(void)> > mTask
Definition: TPZTask.h:38
virtual void Cancel()
Definition: TPZTask.cpp:36
Helper class for ordering the tasks that the user have requested.
Definition: TPZTask.h:18
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
int mPriority
Definition: TPZTask.h:44
bool mSystemTask
Definition: TPZTask.h:43
EProcessingState
Definition: TPZTask.h:31
Simple struct needed by std::priority_queue for ordering the items.
Definition: TPZTask.h:48
int priority() const
Definition: TPZTask.cpp:23
This class implements a reference counter mechanism to administer a dynamically allocated object...