wangzhengquan
2021-01-25 c46be6db32872bfd7c4010b43526b5e6bc0fa6a5
src/queue/shm_queue.h
@@ -33,12 +33,8 @@
  bool full();
  bool empty();
  int push(const ELEM_T &a_data);
  int push_nowait(const ELEM_T &a_data);
  int push_timeout(const ELEM_T &a_data, const struct timespec *timeout);
  int pop(ELEM_T &a_data);
  int pop_nowait(ELEM_T &a_data);
  int pop_timeout(ELEM_T &a_data, struct timespec *timeout);
  int push(const ELEM_T &a_data, const struct timespec *timeout=NULL, int flag=0);
  int pop(ELEM_T &a_data, const struct timespec *timeout=NULL, int flag=0);
  ELEM_T &operator[](unsigned i);
@@ -144,89 +140,40 @@
  return queue->empty();
}
template <typename ELEM_T>
int SHMQueue<ELEM_T>::push(const ELEM_T &a_data) {
  int rv = queue->push(a_data);
  if(rv == -1) {
    return errno;
  } else {
int SHMQueue<ELEM_T>::push(const ELEM_T &a_data, const struct timespec *timeout, int flag) {
  int rv = queue->push(a_data, timeout, flag);
  if(rv == 0) {
    return 0;
  }
  if(rv == ETIMEDOUT)
    return EBUS_TIMEOUT;
  else {
    LoggerFactory::getLogger()->error("LockFreeQueue push_timeout: %s", bus_strerror(rv));
    return rv;
  }
}
template <typename ELEM_T>
int SHMQueue<ELEM_T>::push_nowait(const ELEM_T &a_data) {
  int rv =  queue->push(a_data, NULL, BUS_NOWAIT_FLAG);
  if(rv == -1) {
    if (errno == EAGAIN)
      return EAGAIN;
    else {
        err_msg(errno, "LockFreeQueue push_nowait");
        return errno;
    }
  }
  return 0;
}
int SHMQueue<ELEM_T>::pop(ELEM_T &a_data, const struct timespec *timeout, int flag) {
template <typename ELEM_T>
int SHMQueue<ELEM_T>::push_timeout(const ELEM_T &a_data, const struct timespec *timeout) {
  int rv = queue->push(a_data, timeout, BUS_TIMEOUT_FLAG);
  if(rv == -1) {
    if(errno == ETIMEDOUT)
        return EBUS_TIMEOUT;
    else {
       LoggerFactory::getLogger()->error(errno, "LockFreeQueue push_timeout");
       return errno;
    }
  }
  return 0;
}
template <typename ELEM_T>
int SHMQueue<ELEM_T>::pop(ELEM_T &a_data) {
  LoggerFactory::getLogger()->debug("SHMQueue pop before\n");
  int rv = queue->pop(a_data);
  LoggerFactory::getLogger()->debug("SHMQueue pop before\n");
  if(rv == -1) {
    return errno;
  } else {
  int rv = queue->pop(a_data, timeout, flag);
  if(rv == 0) {
    return 0;
  }
}
template <typename ELEM_T>
int SHMQueue<ELEM_T>::pop_nowait(ELEM_T &a_data) {
  int rv = queue->pop(a_data, NULL, BUS_NOWAIT_FLAG);
  if(rv == -1) {
    if (errno == EAGAIN)
      return errno;
    else {
        LoggerFactory::getLogger()->error(errno, " SHMQueue pop_nowait");
        return errno;
    }
  if(rv == ETIMEDOUT)
    return EBUS_TIMEOUT;
  else {
    LoggerFactory::getLogger()->error("LockFreeQueue pop_timeout: %s", bus_strerror(rv));
    return rv;
  }
  return 0;
}
template <typename ELEM_T>
int SHMQueue<ELEM_T>::pop_timeout(ELEM_T &a_data, struct timespec *timeout) {
  int rv;
  rv = queue->pop(a_data, timeout, BUS_TIMEOUT_FLAG);
  if(rv == -1) {
    if (errno == ETIMEDOUT) {
      return EBUS_TIMEOUT;
    } else {
      LoggerFactory::getLogger()->error(errno, " SHMQueue pop_timeout");
      return errno;
    }
  }
  return 0;
  return rv;
  
}