| | |
| | | #ifndef __LOCK_FREE_QUEUE_H__ |
| | | #define __LOCK_FREE_QUEUE_H__ |
| | | |
| | | #include <stdint.h> // uint32_t |
| | | #include <atomic> |
| | | #include <usg_common.h> |
| | | #include <assert.h> // assert() |
| | | #include "mm.h" |
| | |
| | | class LockFreeQueue |
| | | { |
| | | |
| | | template < typename ELEM_T_ > |
| | | friend class SHMQueue; |
| | | |
| | | private: |
| | | int slots; |
| | | int items; |
| | | public: |
| | | std::atomic_uint reference; |
| | | /// @brief constructor of the class |
| | | LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE); |
| | | protected: |
| | | LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE); |
| | | |
| | | /// @brief destructor of the class. |
| | | /// Note it is not virtual since it is not expected to inherit from this |
| | | /// template |
| | | ~LockFreeQueue(); |
| | | public: |
| | | std::atomic_uint reference; |
| | | /// @brief constructor of the class |
| | | |
| | | |
| | | /// @brief returns the current number of items in the queue |
| | | /// It tries to take a snapshot of the size of the queue, but in busy environments |
| | |
| | | inline bool full(); |
| | | |
| | | inline bool empty(); |
| | | |
| | | inline ELEM_T& operator[](unsigned i); |
| | | |
| | | /// @brief push an element at the tail of the queue |
| | | /// @param the element to insert in the queue |
| | |
| | | |
| | | } |
| | | |
| | | template < |
| | | typename ELEM_T, |
| | | template <typename T> class Q_TYPE> |
| | | ELEM_T& LockFreeQueue<ELEM_T, Q_TYPE>::operator[](unsigned i) { |
| | | return m_qImpl.operator[](i); |
| | | } |
| | | |
| | | template < |
| | | typename ELEM_T, |