From 8ec1d776751f62c43335d36c3427dc1ab2d84a61 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期六, 25 七月 2020 13:52:06 +0800
Subject: [PATCH] commit

---
 src/queue/include/lock_free_queue.h |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/queue/include/lock_free_queue.h b/src/queue/include/lock_free_queue.h
index f34079f..6ba2a00 100644
--- a/src/queue/include/lock_free_queue.h
+++ b/src/queue/include/lock_free_queue.h
@@ -78,7 +78,7 @@
     int items;
    
 public:
-    // int mutex;
+    int mutex;
     LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE);
     
     /// @brief destructor of the class. 
@@ -151,7 +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);
+    mutex = SemUtil::get(IPC_PRIVATE, 1);
 }
 
 template <
@@ -163,6 +163,7 @@
     LoggerFactory::getLogger().debug("LockFreeQueue desctroy");
     SemUtil::remove(slots);
     SemUtil::remove(items);
+    SemUtil::remove(mutex);
 }
 
 template <
@@ -199,13 +200,16 @@
     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");   
     if (SemUtil::dec(slots) == -1) {
         err_msg(errno, "LockFreeQueue push");
         return false;
     }
 
     if ( m_qImpl.push(a_data) ) {
-        SemUtil::inc(items);      
+
+        SemUtil::inc(items);   
+// printf("==================LockFreeQueue push after\n");   
         return true;
     }
     return false;
@@ -243,6 +247,7 @@
 bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push_timeout(const ELEM_T &a_data, struct timespec * timeout)
 {
 
+
     if (SemUtil::dec_timeout(slots, timeout) == -1) {
         if (errno == EAGAIN)
             return false;
@@ -269,13 +274,15 @@
     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");
     if (SemUtil::dec(items) == -1) {
         err_msg(errno, "LockFreeQueue pop");
         return false;
     }
 
     if (m_qImpl.pop(a_data)) {
-        SemUtil::inc(slots);      
+        SemUtil::inc(slots);
+// printf("==================LockFreeQueue pop after\n");      
         return true;
     }
     return false;

--
Gitblit v1.8.0