From 7d3086a481899b03c230eb06a29aa57677041725 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期三, 08 七月 2020 15:07:51 +0800 Subject: [PATCH] update --- squeue/include/lock_free_queue.h | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-) diff --git a/squeue/include/lock_free_queue.h b/squeue/include/lock_free_queue.h index 751db5f..b332bc6 100644 --- a/squeue/include/lock_free_queue.h +++ b/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, -- Gitblit v1.8.0