wangzhengquan
2020-12-23 1b94589dcb8d497d2d8a208efd61a54631f6b84e
src/queue/lock_free_queue.h
@@ -11,6 +11,7 @@
// 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
@@ -200,7 +201,7 @@
    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;
@@ -209,7 +210,7 @@
    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;
@@ -247,18 +248,19 @@
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;
@@ -274,7 +276,8 @@
    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;
@@ -282,7 +285,7 @@
    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;
@@ -319,7 +322,7 @@
    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;
@@ -331,7 +334,7 @@
    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;
@@ -346,6 +349,7 @@
    return m_qImpl.operator[](i);
}
template <
    typename ELEM_T, 
    typename Allocator,