Browse Source

V0.4.6
1、修改了环形队列,修复了一些bug

Apple 4 months ago
parent
commit
a0cae31c4c
1 changed files with 4 additions and 4 deletions
  1. 4 4
      common/RingQueue/RingQueue.hpp

+ 4 - 4
common/RingQueue/RingQueue.hpp

@@ -183,8 +183,8 @@ bool RingQueue<T>::enQueue(T&& data)
 template<typename T>
 void RingQueue<T>::enQueueBlock(const T& data)
 {
-    m_mutex.lock();
-    m_cond_NoFull.wait(m_mutex, [this](){
+    std::unique_lock<std::mutex> lock(m_mutex);
+    m_cond_NoFull.wait(lock, [this](){
         return !isFull();
     });
 
@@ -228,7 +228,7 @@ bool RingQueue<T>::deQueue(T& data)
 template<typename T>
 T& RingQueue<T>::deQueueBlock()
 {
-    std::lock_guard<std::mutex> lock(m_mutex);
+    std::unique_lock<std::mutex> lock(m_mutex);
     m_cond_NoEmpty.wait(lock, [this](){
         return !isEmpty();
     });
@@ -241,7 +241,7 @@ T& RingQueue<T>::deQueueBlock()
         m_rear = -1;
     }
     m_cond_NoFull.notify_all();
-    return std::move(m_queue[tmp]);
+    return m_queue[tmp];
 }
 
 /* 获取队列中第一个值(下一个出队的元素),但是不出队,非阻塞 */