来过。。。
#ifndef __Block_Queue_h__
#define __Block_Queue_h__
#include <queue>
#include <mutex>
#include <condition_variable>
template<class T>
class BlockQueue
{
public:
BlockQueue() {}
~BlockQueue() {}
void Push(T&& value)
{
std::unique_lock<std::mutex> lock(m_mutex);
m_data.push(value);
m_condition.notify_all();
}
void Push(const T& value)
{
std::unique_lock<std::mutex> lock(m_mutex);
m_data.push(value);
m_condition.notify_all();
}
T Pop()
{
std::unique_lock<std::mutex> lock(m_mutex);
while (m_data.empty())
{
m_condition.wait(lock);
}
T value(std::move(m_data.front()));
m_data.pop();
return value;
}
private:
std::queue<T> m_data;
std::mutex m_mutex;
std::condition_variable m_condition;
};
#endif