HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_EventQueue.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_EventQueue_h__
10 #define __PDG_EventQueue_h__
11 
12 #include "PDG_API.h"
13 #include "PDG_Event.h"
14 
15 #include <UT/UT_Set.h>
16 #include <UT/UT_ConcurrentQueue.h>
17 #include <UT/UT_ConcurrentSet.h>
18 #include <UT/UT_Thread.h>
19 #include <UT/UT_RWLock.h>
20 #include <UT/UT_Map.h>
21 
22 #include <SYS/SYS_AtomicInt.h>
23 
24 #include <utility>
25 
26 class PDG_EventEmitter;
27 class PDG_EventHandler;
28 
30 {
31 public:
32  using EventInfo = std::pair<const PDG_EventEmitter*, PDG_Event>;
33 
35  ~PDG_EventQueue();
36 
37  void term();
38 
39  void queueEvent(
40  const PDG_EventEmitter* emitter,
41  const PDG_Event& event);
42 
43  void waitAllEvents();
44 
45  void registerEmitter(PDG_EventEmitter* emitter);
46  void deregisterEmitter(PDG_EventEmitter* emitter);
47 
48  void pause() { myPauseRequests.add(1); }
49  void resume() { myPauseRequests.add(-1); }
50 
52  {
53  public:
55  : myQueue(queue)
56  {
57  queue->pause();
58  }
59 
61  {
62  myQueue->resume();
63  }
64 
65  private:
66  PDG_EventQueue* myQueue = nullptr;
67  };
68 
69 private:
70 #if PDG_EVENT_QUEUE_DEBUG
72 #endif
73 
74  static void* run(void* param);
75 
76  bool myTerminate = false;
77  bool myWaitingEvents = false;
78  UT_Thread* myThread = nullptr;
79 
80  UT_RWLock myEmittersLock;
81  UT_ConcurrentSet<PDG_EventEmitter*> myEmitters;
82  UT_ConcurrentQueue<EventInfo> myEvents;
83 
84  SYS_AtomicInt32 myPauseRequests;
85 
86  static constexpr int theSleepTime = 10;
87 };
88 
89 #endif
Unsorted map container.
Definition: UT_Map.h:107
#define PDG_API
Definition: PDG_API.h:23
struct _cl_event * event
Definition: glcorearb.h:2961
std::pair< const PDG_EventEmitter *, PDG_Event > EventInfo
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the queue
Definition: thread.h:623
GLenum GLfloat param
Definition: glcorearb.h:104
ScopedPause(PDG_EventQueue *queue)
Reader/Writer mutex class.
Definition: UT_RWLock.h:48