| | |
| | | #ifndef __LOCK_FREE_QUEUE_IMPL_MULTIPLE_PRODUCER_H__ |
| | | #define __LOCK_FREE_QUEUE_IMPL_MULTIPLE_PRODUCER_H__ |
| | | #ifndef __ARRAY_LOCK_FREE_QUEUE_IMPL_MULTIPLE_PRODUCER_H__ |
| | | #define __ARRAY_LOCK_FREE_QUEUE_IMPL_MULTIPLE_PRODUCER_H__ |
| | | |
| | | #include <assert.h> // assert() |
| | | #include <sched.h> // sched_yield() |
| | | |
| | | #include "logger_factory.h" |
| | | |
| | | /// @brief implementation of an array based lock free queue with support for |
| | | /// multiple producers |
| | |
| | | /// @brief number of elements in the queue |
| | | std::atomic<uint32_t> m_count; |
| | | #endif |
| | | static int m_reference; |
| | | |
| | | |
| | | |
| | | private: |
| | | /// @brief disable copy constructor declaring it private |
| | | ArrayLockFreeQueue<ELEM_T>(const ArrayLockFreeQueue<ELEM_T> &a_src); |
| | | |
| | | |
| | | }; |
| | | |
| | | |
| | | template <typename ELEM_T> |
| | | int ArrayLockFreeQueue<ELEM_T>::m_reference = 0; |
| | | |
| | | template <typename ELEM_T> |
| | | ArrayLockFreeQueue<ELEM_T>::ArrayLockFreeQueue(size_t qsize): |
| | |
| | | #endif |
| | | { |
| | | m_theQueue = (ELEM_T*)mm_malloc(Q_SIZE * sizeof(ELEM_T)); |
| | | m_reference++; |
| | | |
| | | } |
| | | |
| | |
| | | ArrayLockFreeQueue<ELEM_T>::~ArrayLockFreeQueue() |
| | | { |
| | | std::cout << "destroy ArrayLockFreeQueue\n"; |
| | | m_reference--; |
| | | if(m_reference == 0) { |
| | | mm_free(m_theQueue); |
| | | } |
| | | mm_free(m_theQueue); |
| | | |
| | | } |
| | | |