|
@@ -29,9 +29,8 @@ namespace bx
|
|
|
|
|
|
|
|
void push(Ty* _ptr) // producer only
|
|
void push(Ty* _ptr) // producer only
|
|
|
{
|
|
{
|
|
|
- m_write.lock();
|
|
|
|
|
|
|
+ LwMutexScope $(m_write);
|
|
|
m_queue.push(_ptr);
|
|
m_queue.push(_ptr);
|
|
|
- m_write.unlock();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Ty* peek() // consumer only
|
|
Ty* peek() // consumer only
|
|
@@ -49,6 +48,40 @@ namespace bx
|
|
|
SpScUnboundedQueue<Ty> m_queue;
|
|
SpScUnboundedQueue<Ty> m_queue;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ template <typename Ty>
|
|
|
|
|
+ class MpScUnboundedBlockingQueue
|
|
|
|
|
+ {
|
|
|
|
|
+ BX_CLASS(MpScUnboundedBlockingQueue
|
|
|
|
|
+ , NO_COPY
|
|
|
|
|
+ , NO_ASSIGNMENT
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ 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();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private:
|
|
|
|
|
+ MpScUnboundedQueue<Ty> m_queue;
|
|
|
|
|
+ Semaphore m_sem;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
} // namespace bx
|
|
} // namespace bx
|
|
|
|
|
|
|
|
#endif // BX_MPSCQUEUE_H_HEADER_GUARD
|
|
#endif // BX_MPSCQUEUE_H_HEADER_GUARD
|