HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Task.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Task.h (UT Library, C++)
7  *
8  * COMMENTS: Wrapper for tbb::task
9  */
10 
11 #ifndef __UT_TASK_H_INCLUDED__
12 #define __UT_TASK_H_INCLUDED__
13 
14 #include "UT_API.h"
15 #include "UT_Array.h"
16 #include "UT_TaskScope.h"
17 #include <SYS/SYS_Deprecated.h>
18 #include <tbb/task.h>
19 
20 class UT_TaskList;
21 
22 class UT_API UT_Task : private tbb::task
23 {
24  typedef tbb::task me;
25 
26 public:
27 
30  : myParentScope(nullptr)
31  {
32  }
33 
34  void setParentScope(const UT_TaskScope *parent)
35  {
36  myParentScope = parent;
37  }
38 
39  void setRefCount(int count)
40  {
41  me::set_ref_count(count);
42  }
44  {
45  me::increment_ref_count();
46  }
48  {
49  return me::decrement_ref_count();
50  }
51 
53  {
54  me::recycle_as_continuation();
55  }
57  {
58  me::recycle_as_safe_continuation();
59  }
60  void destroy()
61  {
62  me::destroy(*this);
63  }
64 
65  static void spawnRootAndWait(UT_Task &task)
66  {
68  me::spawn_root_and_wait(task);
69  }
70  void enqueue()
71  {
72  setParentScope(UT_TaskScope::getCurrent());
73  me::enqueue(*this);
74  }
75  void spawnChild(UT_Task &task)
76  {
77  task.setParentScope(myParentScope);
78  me::spawn(task);
79  }
80 
81  /// Should be overriden by derived classes.
82  /// Returns the next task to run, nullptr if none.
83  virtual UT_Task * run() = 0;
84 
85  // Methods imported from tbb::task
86  using me::allocate_root;
87  using me::allocate_child;
88 
90  {
91  me::cancel_group_execution();
92  }
93  bool isCancelled() const
94  {
95  return me::is_cancelled();
96  }
97  void waitForAll()
98  {
99  me::wait_for_all();
100  }
101 
102 private:
103 
104  // Wrapper so that we maintain the UT_TaskScope hierarchy for UT_TaskLock
105  UT_Task * execute() override
106  {
107  UT_TaskScope scope(myParentScope);
108  return run();
109  }
110 
111  friend class UT_TaskList;
112 
113 private:
114 
115  const UT_TaskScope * myParentScope;
116 };
117 
120 {
121 public:
122  UT_Task *run() override
123  {
124  return nullptr;
125  }
126 };
128 
129 #endif // __UT_TASK_H_INCLUDED__
void recycleAsContinuation()
Definition: UT_Task.h:52
static void spawnRootAndWait(UT_Task &task)
Definition: UT_Task.h:65
int decrementRefCount()
Definition: UT_Task.h:47
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
void destroy()
Definition: UT_Task.h:60
UT_Task * run() override
Definition: UT_Task.h:122
static const UT_TaskScope * getCurrent()
Definition: UT_TaskScope.h:96
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
void cancelGroupExecution()
Definition: UT_Task.h:89
#define UT_API
Definition: UT_API.h:14
void enqueue()
Definition: UT_Task.h:70
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
void recycleAsSafeContinuation()
Definition: UT_Task.h:56
void setParentScope(const UT_TaskScope *parent)
Definition: UT_Task.h:34
void setRefCount(int count)
Definition: UT_Task.h:39
void incrementRefCount()
Definition: UT_Task.h:43
void spawnChild(UT_Task &task)
Definition: UT_Task.h:75
void waitForAll()
Definition: UT_Task.h:97
bool isCancelled() const
Definition: UT_Task.h:93
GLint GLsizei count
Definition: glcorearb.h:405