mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added MPSC queue.
This commit is contained in:
54
include/bx/mpscqueue.h
Normal file
54
include/bx/mpscqueue.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef BX_MPSCQUEUE_H_HEADER_GUARD
|
||||
#define BX_MPSCQUEUE_H_HEADER_GUARD
|
||||
|
||||
#include "spscqueue.h"
|
||||
|
||||
namespace bx
|
||||
{
|
||||
template <typename Ty>
|
||||
class MpScUnboundedQueue
|
||||
{
|
||||
BX_CLASS(MpScUnboundedQueue
|
||||
, NO_COPY
|
||||
, NO_ASSIGNMENT
|
||||
);
|
||||
|
||||
public:
|
||||
MpScUnboundedQueue()
|
||||
{
|
||||
}
|
||||
|
||||
~MpScUnboundedQueue()
|
||||
{
|
||||
}
|
||||
|
||||
void push(Ty* _ptr) // producer only
|
||||
{
|
||||
m_write.lock();
|
||||
m_queue.push(_ptr);
|
||||
m_write.unlock();
|
||||
}
|
||||
|
||||
Ty* peek() // consumer only
|
||||
{
|
||||
return m_queue.peek();
|
||||
}
|
||||
|
||||
Ty* pop() // consumer only
|
||||
{
|
||||
return m_queue.pop();
|
||||
}
|
||||
|
||||
private:
|
||||
LwMutex m_write;
|
||||
SpScUnboundedQueue<Ty> m_queue;
|
||||
};
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#endif // BX_MPSCQUEUE_H_HEADER_GUARD
|
||||
@@ -203,4 +203,4 @@ namespace bx
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#endif // BX_RINGBUFFER_H_HEADER_GUARD
|
||||
#endif // BX_SPSCQUEUE_H_HEADER_GUARD
|
||||
|
||||
Reference in New Issue
Block a user