From 59ee841b7e1a3419d0bf755efd95147e1be0492d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 26 Sep 2015 20:27:28 -0700 Subject: [PATCH] Added MpScUnboundedBlockingQueue. --- include/bx/mpscqueue.h | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/include/bx/mpscqueue.h b/include/bx/mpscqueue.h index f0d91e1..d7f3966 100644 --- a/include/bx/mpscqueue.h +++ b/include/bx/mpscqueue.h @@ -29,9 +29,8 @@ namespace bx void push(Ty* _ptr) // producer only { - m_write.lock(); + LwMutexScope $(m_write); m_queue.push(_ptr); - m_write.unlock(); } Ty* peek() // consumer only @@ -49,6 +48,40 @@ namespace bx SpScUnboundedQueue m_queue; }; + template + 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 m_queue; + Semaphore m_sem; + }; + } // namespace bx #endif // BX_MPSCQUEUE_H_HEADER_GUARD