wangzhengquan
2020-07-08 7d3086a481899b03c230eb06a29aa57677041725
squeue/include/lock_free_queue.h
@@ -1,8 +1,6 @@
#ifndef __LOCK_FREE_QUEUE_H__
#define __LOCK_FREE_QUEUE_H__
#include <stdint.h>     // uint32_t
#include <atomic>
#include <usg_common.h>
#include <assert.h> // assert()
#include "mm.h" 
@@ -72,18 +70,23 @@
class LockFreeQueue
{
    template < typename ELEM_T_ >
    friend class SHMQueue;
private:
    int slots;
    int items;
public:
    std::atomic_uint reference;
    /// @brief constructor of the class
    LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE);
protected:
     LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE);
    
    /// @brief destructor of the class. 
    /// Note it is not virtual since it is not expected to inherit from this
    /// template
    ~LockFreeQueue();
public:
    std::atomic_uint reference;
    /// @brief constructor of the class
    /// @brief returns the current number of items in the queue
    /// It tries to take a snapshot of the size of the queue, but in busy environments
@@ -102,6 +105,8 @@
    inline bool full();
    inline bool empty();
    inline ELEM_T& operator[](unsigned i);
    /// @brief push an element at the tail of the queue
    /// @param the element to insert in the queue
@@ -300,6 +305,12 @@
    
}
template <
    typename ELEM_T,
    template <typename T> class Q_TYPE>
ELEM_T& LockFreeQueue<ELEM_T, Q_TYPE>::operator[](unsigned i) {
    return m_qImpl.operator[](i);
}
template <
    typename ELEM_T,