Files
bx/include/bx/mpscqueue.h
Branimir Karadžić 10461810b0 Cleanup.
2017-02-16 21:47:19 -08:00

76 lines
1.1 KiB
C++

/*
* Copyright 2010-2017 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#ifndef BX_MPSCQUEUE_H_HEADER_GUARD
#define BX_MPSCQUEUE_H_HEADER_GUARD
#include "mutex.h"
#include "spscqueue.h"
namespace bx
{
///
template <typename Ty>
class MpScUnboundedQueueT
{
BX_CLASS(MpScUnboundedQueueT
, NO_COPY
, NO_ASSIGNMENT
);
public:
///
MpScUnboundedQueueT();
///
~MpScUnboundedQueueT();
///
void push(Ty* _ptr); // producer only
///
Ty* peek(); // consumer only
///
Ty* pop(); // consumer only
private:
Mutex m_write;
SpScUnboundedQueueT<Ty> m_queue;
};
///
template <typename Ty>
class MpScUnboundedBlockingQueue
{
BX_CLASS(MpScUnboundedBlockingQueue
, NO_COPY
, NO_ASSIGNMENT
);
public:
///
MpScUnboundedBlockingQueue();
///
~MpScUnboundedBlockingQueue();
///
void push(Ty* _ptr); // producer only
///
Ty* pop(); // consumer only
private:
MpScUnboundedQueueT<Ty> m_queue;
Semaphore m_sem;
};
} // namespace bx
#include "inline/mpscqueue.inl"
#endif // BX_MPSCQUEUE_H_HEADER_GUARD