Sfoglia il codice sorgente

V0.4.8
1、环形队列还有些问题

Apple 4 mesi fa
parent
commit
327632a237
1 ha cambiato i file con 4 aggiunte e 3 eliminazioni
  1. 4 3
      common/RingQueue/RingQueue.hpp

+ 4 - 3
common/RingQueue/RingQueue.hpp

@@ -53,7 +53,7 @@ public:
     /* 出队 */
     bool deQueue(T& data);
     /* 阻塞出队 */
-    T& deQueueBlock();
+    T deQueueBlock();
 
     /* 获取队列中第一个值(下一个出队的元素),但是不出队,非阻塞 */
     bool front(T& t);
@@ -245,7 +245,7 @@ bool RingQueue<T>::deQueue(T& data)
 
 /* 出队 */
 template<typename T>
-T& RingQueue<T>::deQueueBlock()
+T RingQueue<T>::deQueueBlock()
 {
     std::unique_lock<std::mutex> lock(m_mutex);
     m_cond_NoEmpty.wait(lock, [this](){
@@ -259,8 +259,9 @@ T& RingQueue<T>::deQueueBlock()
         m_front = -1;
         m_rear = -1;
     }
+    auto ret = m_queue[tmp];
     m_cond_NoFull.notify_all();
-    return m_queue[tmp];
+    return ret;
 }
 
 /* 获取队列中第一个值(下一个出队的元素),但是不出队,非阻塞 */