| | |
| | | // default Queue size |
| | | #define LOCK_FREE_Q_DEFAULT_SIZE 16 |
| | | |
| | | // static Logger *logger = LoggerFactory::getLogger(); |
| | | // define this macro if calls to "size" must return the real size of the |
| | | // queue. If it is undefined that function will try to take a snapshot of |
| | | // the queue, but returned value might be bogus |
| | |
| | | template <typename T, typename AT> class Q_TYPE> |
| | | bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data) |
| | | { |
| | | // printf("==================LockFreeQueue push before\n"); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push before\n"); |
| | | if (SemUtil::dec(slots) == -1) { |
| | | err_msg(errno, "LockFreeQueue push"); |
| | | return false; |
| | |
| | | if ( m_qImpl.push(a_data) ) { |
| | | |
| | | SemUtil::inc(items); |
| | | // printf("==================LockFreeQueue push after\n"); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push after\n"); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push_timeout(const ELEM_T &a_data, const struct timespec * timeout) |
| | | { |
| | | |
| | | |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push_timeout before\n"); |
| | | if (SemUtil::dec_timeout(slots, timeout) == -1) { |
| | | if (errno == EAGAIN) |
| | | return false; |
| | | else { |
| | | // err_msg(errno, "LockFreeQueue push_timeout"); |
| | | err_msg(errno, "LockFreeQueue push_timeout"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if (m_qImpl.push(a_data)){ |
| | | SemUtil::inc(items); |
| | | SemUtil::inc(items); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push_timeout after\n"); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | template <typename T, typename AT> class Q_TYPE> |
| | | bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop(ELEM_T &a_data) |
| | | { |
| | | // printf("==================LockFreeQueue pop before\n"); |
| | | |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before\n"); |
| | | if (SemUtil::dec(items) == -1) { |
| | | err_msg(errno, "LockFreeQueue pop"); |
| | | return false; |
| | |
| | | |
| | | if (m_qImpl.pop(a_data)) { |
| | | SemUtil::inc(slots); |
| | | // printf("==================LockFreeQueue pop after\n"); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n"); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | template <typename T, typename AT> class Q_TYPE> |
| | | bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop_timeout(ELEM_T &a_data, struct timespec * timeout) |
| | | { |
| | | // printf("==================LockFreeQueue pop_timeout before\n"); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop_timeout before\n"); |
| | | if (SemUtil::dec_timeout(items, timeout) == -1) { |
| | | if (errno == EAGAIN) |
| | | return false; |
| | |
| | | |
| | | if (m_qImpl.pop(a_data)) { |
| | | SemUtil::inc(slots); |
| | | // printf("==================LockFreeQueue pop_timeout after\n"); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop_timeout after\n"); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | return m_qImpl.operator[](i); |
| | | } |
| | | |
| | | |
| | | template < |
| | | typename ELEM_T, |
| | | typename Allocator, |