ezEngine  Milestone 7
MessageQueue.h
1 
2 #pragma once
3 
4 #include <Foundation/Communication/Message.h>
5 #include <Foundation/Containers/Deque.h>
6 #include <Foundation/Threading/Lock.h>
7 #include <Foundation/Threading/Mutex.h>
8 
16 template <typename MetaDataType>
18 {
19 public:
20  struct Entry
21  {
22  EZ_DECLARE_POD_TYPE();
23 
24  ezMessage* m_pMessage;
25  MetaDataType m_MetaData;
26  };
27 
28 protected:
29 
31  ezMessageQueueBase(ezAllocatorBase* pAllocator); // [tested]
32 
34  ezMessageQueueBase(const ezMessageQueueBase& rhs, ezAllocatorBase* pAllocator);
35 
37  ~ezMessageQueueBase(); // [tested]
38 
40  void operator=(const ezMessageQueueBase& rhs);
41 
42 public:
44  Entry& operator[](ezUInt32 uiIndex); // [tested]
45 
47  const Entry& operator[](ezUInt32 uiIndex) const; // [tested]
48 
50  ezUInt32 GetCount() const;
51 
53  bool IsEmpty() const;
54 
56  void Clear();
57 
59  void Reserve(ezUInt32 uiCount);
60 
62  void Compact();
63 
65  void Enqueue(ezMessage* pMessage, const MetaDataType& metaData); // [tested]
66 
68  bool TryDequeue(ezMessage*& out_pMessage, MetaDataType& out_metaData); // [tested]
69 
71  bool TryPeek(ezMessage*& out_pMessage, MetaDataType& out_metaData); // [tested]
72 
74  Entry& Peek();
75 
77  void Dequeue();
78 
80  template <typename Comparer>
81  void Sort(const Comparer& comparer); // [tested]
82 
84  void Acquire(); // [tested]
85 
87  void Release(); // [tested]
88 
89 private:
91  ezMutex m_Mutex;
92 };
93 
95 template <typename MetaDataType, typename AllocatorWrapper = ezDefaultAllocatorWrapper>
96 class ezMessageQueue : public ezMessageQueueBase<MetaDataType>
97 {
98 public:
100  ezMessageQueue(ezAllocatorBase* pAllocator);
101 
104 
105  void operator=(const ezMessageQueue<MetaDataType, AllocatorWrapper>& rhs);
106  void operator=(const ezMessageQueueBase<MetaDataType>& rhs);
107 };
108 
109 #include <Foundation/Communication/Implementation/MessageQueue_inl.h>
110