| | |
| | | typename Allocator, |
| | | template<typename T, typename AT> class Q_TYPE> |
| | | int LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data, const struct timespec *timeout, int flag) { |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push before\n"); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue push before\n"); |
| | | sigset_t mask_all, pre; |
| | | sigfillset(&mask_all); |
| | | |
| | | sigprocmask(SIG_BLOCK, &mask_all, &pre); |
| | | |
| | | if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) { |
| | | if (psem_trywait(&slots) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) { |
| | | if (psem_timedwait(&slots, timeout) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else { |
| | | if (psem_wait(&slots) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (m_qImpl.push(a_data)) { |
| | | psem_post(&items); |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push after\n"); |
| | | return 0; |
| | | } |
| | | return -1; |
| | | |
| | | LABEL_FAILTURE: |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | return errno; |
| | | |
| | | } |
| | | |
| | |
| | | typename Allocator, |
| | | template<typename T, typename AT> class Q_TYPE> |
| | | int LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop(ELEM_T &a_data, const struct timespec *timeout, int flag) { |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before...."); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before...."); |
| | | |
| | | sigset_t mask_all, pre; |
| | | sigfillset(&mask_all); |
| | | |
| | | sigprocmask(SIG_BLOCK, &mask_all, &pre); |
| | | |
| | | if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) { |
| | | if (psem_trywait(&items) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) { |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before. flag=%d , %d\n", flag, timeout->tv_sec); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before. flag=%d , %d\n", flag, timeout->tv_sec); |
| | | if (psem_timedwait(&items, timeout) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else { |
| | | if (psem_wait(&items) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (m_qImpl.pop(a_data)) { |
| | | psem_post(&slots); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n"); |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n"); |
| | | return 0; |
| | | } |
| | | return -1; |
| | | |
| | | LABEL_FAILTURE: |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | return errno; |
| | | } |
| | | |
| | | template<typename ELEM_T, |