#ifndef _INCLUDED_QUEUE_ #define _INCLUDED_QUEUE_ #include #include #include template class DataQueue { public: DataQueue() = default; DataQueue(DataQueue&) = delete; void Push(T data) { std::lock_guard lock(m_Mutex); m_Queue.push_back(data); m_Cond.notify_one(); } T Pop() { std::unique_lock lock(m_Mutex); while (m_Queue.empty()) { m_Cond.wait(lock); } T data = m_Queue.front(); m_Queue.pop_front(); return data; } bool Empty() { std::lock_guard lock(m_Mutex); return m_Queue.empty(); } size_t Size() { std::lock_guard lock(m_Mutex); return m_Queue.size(); } void Clear() { std::lock_guard lock(m_Mutex); m_Queue.clear(); } protected: std::list m_Queue; std::mutex m_Mutex; std::condition_variable m_Cond; }; #endif