HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TaskGroup.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_TaskGroup.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_TASKGROUP_H_INCLUDED__
12 #define __UT_TASKGROUP_H_INCLUDED__
13 
14 #ifndef __TBB_show_deprecation_message_task_H
15  #define __TBB_show_deprecation_message_task_H
16  #define UT_TASKGROUP_RESTORE_DEPRECATION_MESSAGE
17 #endif
18 
19 #include "UT_API.h"
20 #include <tbb/task.h>
21 #include <tbb/task_group.h>
22 #include <utility>
23 
24 class UT_API UT_TaskGroupContext : private tbb::task_group_context
25 {
26  typedef tbb::task_group_context me;
27 
28 public:
29 
30  enum KindType
31  {
32  ISOLATED = me::isolated,
33  BOUND = me::bound
34  };
35 
36  /// Constructs an empty task_group_context.
37  ///
38  /// If relation_to_parent is bound, the task_group_context will become a
39  /// child of the innermost running task's group when it is first spawned.
40  /// If this call is made directly from the user thread, the effect will be
41  /// as if relation_to_parent were isolated. If relation_to_parent is
42  /// isolated, it has no parent task_group_context.
43  UT_TaskGroupContext(KindType relation_to_parent = BOUND)
44  : task_group_context((kind_type)relation_to_parent)
45  {
46  }
47 
48  /// Destroys an empty task_group_context. The behavior is undefined if
49  /// there are still extant tasks associated with this task_group_context.
50  ~UT_TaskGroupContext() = default;
51 
52  /// Reinitializes this to uncancelled state.
53  ///
54  /// @warn This method is only safe to call once all tasks associated with
55  /// the group's subordinate groups have completed. This method must not be
56  /// invoked concurrently by multiple threads.
57  void reset()
58  {
59  me::reset();
60  }
61 
62  /// Requests that tasks in group be cancelled.
63  ///
64  /// @return False if group is already cancelled; true otherwise. If
65  /// concurrently called by multiple threads, exactly one call
66  /// returns true and the rest return false.
68  {
69  return me::cancel_group_execution();
70  }
71 
72  /// @return True if group has received cancellation.
74  {
75  return me::is_group_execution_cancelled();
76  }
77 
78  /// Cancel the entire current task group context when run within a task
80  {
81  // TODO: In oneTBB, this becomes,
82  // current_context()->cancel_group_execution()
83  tbb::task::self().cancel_group_execution();
84  }
85 };
86 
87 class UT_API UT_TaskGroup : private tbb::task_group
88 {
89  typedef tbb::task_group me;
90 
91 public:
93  : tbb::task_group()
94  {
95  }
97  {
98  }
99 
100  template <typename F>
101  void run(F &&f)
102  {
103  me::run(std::forward<F>(f));
104  }
105 
106  template <typename F>
107  void run(tbb::task_handle<F> &f)
108  {
109  me::run(f);
110  }
111 
112  template <typename F>
113  void runAndWait(const F &f)
114  {
115  me::run_and_wait(f);
116  }
117 
118  template <typename F>
119  void runAndWait(tbb::task_handle<F> &f)
120  {
121  me::run_and_wait(f);
122  }
123 
124  // American English
125  bool isCanceling() { return me::is_canceling(); }
126  // British English
127  bool isCancelling() { return me::is_canceling(); }
128 
129  tbb::task_group_status wait() { return me::wait(); }
130  void cancel() { me::cancel(); }
131 };
132 
133 #ifdef UT_TASKGROUP_RESTORE_DEPRECATION_MESSAGE
134  #undef __TBB_show_deprecation_message_task_H
135  #undef UT_TASKGROUP_RESTORE_DEPRECATION_MESSAGE
136 #endif
137 
138 #endif // __UT_TASKGROUP_H_INCLUDED__
bool isCancelling()
Definition: UT_TaskGroup.h:127
UT_TaskGroupContext(KindType relation_to_parent=BOUND)
Definition: UT_TaskGroup.h:43
#define UT_API
Definition: UT_API.h:14
void runAndWait(tbb::task_handle< F > &f)
Definition: UT_TaskGroup.h:119
tbb::task_group_status wait()
Definition: UT_TaskGroup.h:129
void runAndWait(const F &f)
Definition: UT_TaskGroup.h:113
void run(F &&f)
Definition: UT_TaskGroup.h:101
void run(tbb::task_handle< F > &f)
Definition: UT_TaskGroup.h:107
GLboolean reset
Definition: glew.h:4989
*tasks wait()
bool cancelGroupExecution()
Definition: UT_TaskGroup.h:67
GLfloat f
Definition: glcorearb.h:1925
bool isCanceling()
Definition: UT_TaskGroup.h:125
bool isGroupExecutionCancelled() const
Definition: UT_TaskGroup.h:73
static void cancelCurrentGroupExecution()
Cancel the entire current task group context when run within a task.
Definition: UT_TaskGroup.h:79