wangzhengquan
2021-01-25 0182d4f033f2ef736005ec300c2b330614d10cad
src/queue/lock_free_queue.h
@@ -207,63 +207,79 @@
template<typename ELEM_T,
        typename Allocator,
        template<typename T, typename AT> class Q_TYPE>
      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");
    if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) {
        if (psem_trywait(&slots) == -1) {
            return -1;
        }
    } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) {
        if (psem_timedwait(&slots, timeout) == -1) {
            return -1;
        }
    } else {
        if (psem_wait(&slots) == -1) {
            return -1;
        }
    }
  // 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) {
          goto LABEL_FAILTURE;
      }
  } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) {
      if (psem_timedwait(&slots, timeout) == -1) {
          goto LABEL_FAILTURE;
      }
  } else {
      if (psem_wait(&slots) == -1) {
          goto LABEL_FAILTURE;
      }
  }
    if (m_qImpl.push(a_data)) {
        psem_post(&items);
        LoggerFactory::getLogger()->debug("==================LockFreeQueue push after\n");
        return 0;
    }
    return -1;
  if (m_qImpl.push(a_data)) {
    psem_post(&items);
    sigprocmask(SIG_SETMASK, &pre, NULL);
    LoggerFactory::getLogger()->debug("==================LockFreeQueue push after\n");
    return 0;
  }
LABEL_FAILTURE:
  sigprocmask(SIG_SETMASK, &pre, NULL);
  return errno;
}
template<typename ELEM_T,
        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\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(&items) == -1) {
         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);
      if (psem_timedwait(&items, timeout) == -1) {
          goto LABEL_FAILTURE;
      }
  } else {
      if (psem_wait(&items) == -1) {
          goto LABEL_FAILTURE;
      }
  }
    if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) {
        if (psem_trywait(&items) == -1) {
            return -1;
        }
    } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) {
        if (psem_timedwait(&items, timeout) == -1) {
            return -1;
        }
    } else {
        if (psem_wait(&items) == -1) {
            return -1;
        }
    }
  if (m_qImpl.pop(a_data)) {
      psem_post(&slots);
      sigprocmask(SIG_SETMASK, &pre, NULL);
      // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n");
      return 0;
  }
    if (m_qImpl.pop(a_data)) {
        psem_post(&slots);
        LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n");
        return 0;
    }
    return -1;
LABEL_FAILTURE:
  sigprocmask(SIG_SETMASK, &pre, NULL);
  return errno;
}
template<typename ELEM_T,