|
|
@@ -6,48 +6,42 @@
|
|
|
#ifndef BX_MPSCQUEUE_H_HEADER_GUARD
|
|
|
#define BX_MPSCQUEUE_H_HEADER_GUARD
|
|
|
|
|
|
+#include "mutex.h"
|
|
|
#include "spscqueue.h"
|
|
|
|
|
|
namespace bx
|
|
|
{
|
|
|
+ ///
|
|
|
template <typename Ty>
|
|
|
- class MpScUnboundedQueue
|
|
|
+ class MpScUnboundedQueueT
|
|
|
{
|
|
|
- BX_CLASS(MpScUnboundedQueue
|
|
|
+ BX_CLASS(MpScUnboundedQueueT
|
|
|
, NO_COPY
|
|
|
, NO_ASSIGNMENT
|
|
|
);
|
|
|
|
|
|
public:
|
|
|
- MpScUnboundedQueue()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- ~MpScUnboundedQueue()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- void push(Ty* _ptr) // producer only
|
|
|
- {
|
|
|
- MutexScope lock(m_write);
|
|
|
- m_queue.push(_ptr);
|
|
|
- }
|
|
|
-
|
|
|
- Ty* peek() // consumer only
|
|
|
- {
|
|
|
- return m_queue.peek();
|
|
|
- }
|
|
|
-
|
|
|
- Ty* pop() // consumer only
|
|
|
- {
|
|
|
- return m_queue.pop();
|
|
|
- }
|
|
|
+ ///
|
|
|
+ MpScUnboundedQueueT();
|
|
|
+
|
|
|
+ ///
|
|
|
+ ~MpScUnboundedQueueT();
|
|
|
+
|
|
|
+ ///
|
|
|
+ void push(Ty* _ptr); // producer only
|
|
|
+
|
|
|
+ ///
|
|
|
+ Ty* peek(); // consumer only
|
|
|
+
|
|
|
+ ///
|
|
|
+ Ty* pop(); // consumer only
|
|
|
|
|
|
private:
|
|
|
Mutex m_write;
|
|
|
- SpScUnboundedQueue<Ty> m_queue;
|
|
|
+ SpScUnboundedQueueT<Ty> m_queue;
|
|
|
};
|
|
|
|
|
|
+ ///
|
|
|
template <typename Ty>
|
|
|
class MpScUnboundedBlockingQueue
|
|
|
{
|
|
|
@@ -57,31 +51,25 @@ namespace bx
|
|
|
);
|
|
|
|
|
|
public:
|
|
|
- MpScUnboundedBlockingQueue()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- ~MpScUnboundedBlockingQueue()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- void push(Ty* _ptr) // producer only
|
|
|
- {
|
|
|
- m_queue.push(_ptr);
|
|
|
- m_sem.post();
|
|
|
- }
|
|
|
-
|
|
|
- Ty* pop() // consumer only
|
|
|
- {
|
|
|
- m_sem.wait();
|
|
|
- return m_queue.pop();
|
|
|
- }
|
|
|
+ ///
|
|
|
+ MpScUnboundedBlockingQueue();
|
|
|
+
|
|
|
+ ///
|
|
|
+ ~MpScUnboundedBlockingQueue();
|
|
|
+
|
|
|
+ ///
|
|
|
+ void push(Ty* _ptr); // producer only
|
|
|
+
|
|
|
+ ///
|
|
|
+ Ty* pop(); // consumer only
|
|
|
|
|
|
private:
|
|
|
- MpScUnboundedQueue<Ty> m_queue;
|
|
|
+ MpScUnboundedQueueT<Ty> m_queue;
|
|
|
Semaphore m_sem;
|
|
|
};
|
|
|
|
|
|
} // namespace bx
|
|
|
|
|
|
+#include "mpscqueue.inl"
|
|
|
+
|
|
|
#endif // BX_MPSCQUEUE_H_HEADER_GUARD
|