HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_WorkItemStateTracker.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 * COMMENTS:
7 */
8 
9 #ifndef __PDG_WORKITEM_STATETRACKER_H__
10 #define __PDG_WORKITEM_STATETRACKER_H__
11 
12 #include "PDG_API.h"
13 #include "PDG_NodeTypes.h"
14 #include "PDG_WorkItemTypes.h"
15 
16 #include <UT/UT_TBBSpinLock.h>
17 
18 /*
19  * Helper class that maintains a list of work item state counts
20  */
22 {
23 public:
25  { reset(); }
26 
27  inline void reset()
28  {
29  UT_TBBSpinLock::Scope lock(myLock);
30 
31  myWorkItemCount = 0;
32  for (int i = 0;
34  i++)
35  {
36  myStateCounts[i] = 0;
37  }
38  }
39 
40  inline int workItemCount() const
41  { return myWorkItemCount; }
42 
43  inline int stateCount(PDG_WorkItemState state) const
44  { return stateCounter(state); }
45 
46  inline void addWorkItem(PDG_WorkItemState state)
47  {
48  UT_TBBSpinLock::Scope lock(myLock);
49  stateCounter(state) += 1;
50  myWorkItemCount += 1;
51  }
52 
53  inline void removeWorkItem(PDG_WorkItemState state)
54  {
55  UT_TBBSpinLock::Scope lock(myLock);
56  stateCounter(state) -= 1;
57  myWorkItemCount -= 1;
58  }
59 
60  inline void updateWorkItem(
61  PDG_WorkItemState prev,
63  {
64  UT_TBBSpinLock::Scope lock(myLock);
65  stateCounter(prev) -= 1;
66  stateCounter(cur) += 1;
67  }
68 
69  template <typename T>
70  inline void stateCounts(UT_Array<T>& array) const
71  {
72  exint size =
74  array.setSize(size);
75 
76  for (exint i = 0; i < size; i++)
77  array[i] = (T)(myStateCounts[i]);
78  }
79 
80  PDG_NodeState nodeState(bool is_active, bool is_generated) const;
81  fpreal nodeProgress() const;
82 
83 private:
84  inline exint& stateCounter(PDG_WorkItemState state)
85  { return myStateCounts[(int)state]; }
86  inline const exint& stateCounter(PDG_WorkItemState state) const
87  { return myStateCounts[(int)state]; }
88 
89 private:
90  exint myWorkItemCount;
92  mutable UT_TBBSpinLock myLock;
93 };
94 
95 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
#define PDG_API
Definition: PDG_API.h:23
int64 exint
Definition: SYS_Types.h:125
void stateCounts(UT_Array< T > &array) const
void setSize(exint newsize)
Definition: UT_Array.h:666
GLboolean reset
Definition: glad.h:5138
PDG_WorkItemState
Enum of possible work item states.
PDG_NodeState
Node state, used for UI/progress reporting.
Definition: PDG_NodeTypes.h:68
GLsizeiptr size
Definition: glcorearb.h:664
void updateWorkItem(PDG_WorkItemState prev, PDG_WorkItemState cur)
fpreal64 fpreal
Definition: SYS_Types.h:277
int stateCount(PDG_WorkItemState state) const
void removeWorkItem(PDG_WorkItemState state)
The number of states.
void addWorkItem(PDG_WorkItemState state)