| | |
| | | class LockFreeQueue |
| | | { |
| | | |
| | | template < typename ELEM_T_ > |
| | | friend class SHMQueue; |
| | | |
| | | private: |
| | | int slots; |
| | | int items; |
| | | protected: |
| | | LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE); |
| | | |
| | | public: |
| | | // int mutex; |
| | | 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 |
| | | |
| | |
| | | // std::cout << "LockFreeQueue init reference=" << reference << std::endl; |
| | | slots = SemUtil::get(IPC_PRIVATE, qsize); |
| | | items = SemUtil::get(IPC_PRIVATE, 0); |
| | | // mutex = SemUtil::get(IPC_PRIVATE, 1); |
| | | } |
| | | |
| | | template < |
| | |
| | | bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data) |
| | | { |
| | | if (SemUtil::dec(slots) == -1) { |
| | | err_exit(errno, "push"); |
| | | err_msg(errno, "LockFreeQueue push"); |
| | | return false; |
| | | } |
| | | |
| | | if ( m_qImpl.push(a_data) ) { |
| | |
| | | if (SemUtil::dec_nowait(slots) == -1) { |
| | | if (errno == EAGAIN) |
| | | return false; |
| | | else |
| | | err_exit(errno, "push_nowait"); |
| | | else { |
| | | err_msg(errno, "LockFreeQueue push_nowait"); |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | if ( m_qImpl.push(a_data)) { |
| | |
| | | if (SemUtil::dec_timeout(slots, timeout) == -1) { |
| | | if (errno == EAGAIN) |
| | | return false; |
| | | else |
| | | err_exit(errno, "push_timeout"); |
| | | else { |
| | | err_msg(errno, "LockFreeQueue push_timeout"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if (m_qImpl.push(a_data)){ |
| | |
| | | typename Allocator, |
| | | template <typename T, typename AT> class Q_TYPE> |
| | | void * LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::operator new(size_t size){ |
| | | return Allocator::malloc(size); |
| | | return Allocator::allocate(size); |
| | | } |
| | | |
| | | template < |
| | |
| | | typename Allocator, |
| | | template <typename T, typename AT> class Q_TYPE> |
| | | void LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::operator delete(void *p) { |
| | | return Allocator::free(p); |
| | | return Allocator::deallocate(p); |
| | | } |
| | | |
| | | // include implementation files |