Added MpScUnboundedBlockingQueue.

This commit is contained in:
Branimir Karadžić
2015-09-26 20:27:28 -07:00
parent 2ebb93da06
commit 59ee841b7e

View File

@@ -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<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
#endif // BX_MPSCQUEUE_H_HEADER_GUARD