HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_TaskArena.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_TaskArena.h (UT Library, C++)
7  *
8  * COMMENTS: Wrapper for tbb::task_arena
9  */
10 
11 #ifndef __UT_TASKARENA_H_INCLUDED__
12 #define __UT_TASKARENA_H_INCLUDED__
13 
14 #include "UT_API.h"
15 #include "UT_NonCopyable.h"
16 #include <SYS/SYS_AtomicInt.h>
17 #include <stddef.h>
18 
19 
20 /// @file
21 /// @class UT_TaskArena
22 ///
23 /// Simple wrapper for running code within a tbb::task_arena. For most usages,
24 /// you want to do this if you're going to spawn tasks with a lock held.
26 {
27 public:
28  static const int automatic = -1;
29 
30  UT_TaskArena(int max_concurrency = automatic,
31  unsigned reserved_for_masters = 1);
32  ~UT_TaskArena();
33 
34  template <typename F>
35  void execute(F &functor)
36  {
37  internalExecute(&UT_TaskArena::callback<F>, &functor);
38  }
39 
40  template <typename F>
41  void execute(const F &functor)
42  {
43  internalExecute(&UT_TaskArena::callbackConst<F>, &functor);
44  }
45 
46  template <typename M, typename F>
47  static void
48  lockedExecute(M &mutex, F &functor)
49  {
50  typename M::Scope scope(mutex);
51  UT_TaskArena arena;
52  arena.execute(functor);
53  }
54 
55  template <typename M, typename F>
56  static void
57  lockedExecute(M &mutex, const F &functor)
58  {
59  typename M::Scope scope(mutex);
60  UT_TaskArena arena;
61  arena.execute(functor);
62  }
63 
64  // Debug counter. Only modified on debug builds
66 
67 private:
68 
69  template <typename F>
70  static void callback(void *data)
71  {
72  (*reinterpret_cast<F *>(data))();
73  }
74  template <typename F>
75  static void callbackConst(const void *data)
76  {
77  (*reinterpret_cast<const F *>(data))();
78  }
79 
80  void internalExecute(void (*callback)(void *), void *data);
81  void internalExecute(void (*callback)(const void *), const void *data);
82 
83 private:
84  static const size_t SIZEOF_ARENA = 40;
85  uint8 myArena[SIZEOF_ARENA];
86 };
87 
88 #endif // __UT_TASKARENA_H_INCLUDED__
static void lockedExecute(M &mutex, const F &functor)
Definition: UT_TaskArena.h:57
void execute(F &functor)
Definition: UT_TaskArena.h:35
#define UT_API
Definition: UT_API.h:12
static void lockedExecute(M &mutex, F &functor)
Definition: UT_TaskArena.h:48
GLboolean * data
Definition: glcorearb.h:130
static SYS_AtomicInt32 theArenaCount
Definition: UT_TaskArena.h:65
void execute(const F &functor)
Definition: UT_TaskArena.h:41
unsigned char uint8
Definition: SYS_Types.h:31