mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-18 04:53:06 +01:00
Added MpScUnboundedBlockingQueue.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user