From f85c9b875b060681b51f57b15074ba1c7c9f5636 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 20 七月 2020 11:10:02 +0800 Subject: [PATCH] update --- queue/include/lock_free_queue.h | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 deletions(-) diff --git a/queue/include/lock_free_queue.h b/queue/include/lock_free_queue.h index ca8adb4..f34079f 100644 --- a/queue/include/lock_free_queue.h +++ b/queue/include/lock_free_queue.h @@ -73,20 +73,18 @@ class LockFreeQueue { - template < typename ELEM_T_ > - friend class SHMQueue; - private: int slots; int items; -protected: - LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE); + +public: + // int mutex; + 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 @@ -153,6 +151,7 @@ // std::cout << "LockFreeQueue init reference=" << reference << std::endl; slots = SemUtil::get(IPC_PRIVATE, qsize); items = SemUtil::get(IPC_PRIVATE, 0); + // mutex = SemUtil::get(IPC_PRIVATE, 1); } template < @@ -201,7 +200,8 @@ bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data) { if (SemUtil::dec(slots) == -1) { - err_exit(errno, "push"); + err_msg(errno, "LockFreeQueue push"); + return false; } if ( m_qImpl.push(a_data) ) { @@ -221,8 +221,11 @@ if (SemUtil::dec_nowait(slots) == -1) { if (errno == EAGAIN) return false; - else - err_exit(errno, "push_nowait"); + else { + err_msg(errno, "LockFreeQueue push_nowait"); + return false; + } + } if ( m_qImpl.push(a_data)) { @@ -243,8 +246,10 @@ if (SemUtil::dec_timeout(slots, timeout) == -1) { if (errno == EAGAIN) return false; - else - err_exit(errno, "push_timeout"); + else { + err_msg(errno, "LockFreeQueue push_timeout"); + return false; + } } if (m_qImpl.push(a_data)){ @@ -337,7 +342,7 @@ typename Allocator, template <typename T, typename AT> class Q_TYPE> void * LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::operator new(size_t size){ - return Allocator::malloc(size); + return Allocator::allocate(size); } template < @@ -345,7 +350,7 @@ typename Allocator, template <typename T, typename AT> class Q_TYPE> void LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::operator delete(void *p) { - return Allocator::free(p); + return Allocator::deallocate(p); } // include implementation files -- Gitblit v1.8.0