1 #ifndef teca_threadsafe_queue_h
2 #define teca_threadsafe_queue_h
4 #include "teca_config.h"
8 #include <condition_variable>
20 typename std::queue<T>::size_type size()
const;
23 void push(
const T &val);
40 mutable std::mutex m_mutex;
41 std::queue<T> m_queue;
42 std::condition_variable m_ready;
43 std::condition_variable m_empty;
51 std::lock_guard<std::mutex> lock(other.m_mutex);
52 std::queue<T> tmp(other.m_queue);
61 std::lock(m_mutex, other.m_mutex);
62 std::lock_guard<std::mutex> lock(m_mutex, std::adopt_lock);
63 std::lock_guard<std::mutex> lock_other(other.m_mutex, std::adopt_lock);
64 std::queue<T> tmp(other.m_queue);
72 std::lock(m_mutex, other.m_mutex);
73 std::lock_guard<std::mutex> lock(m_mutex, std::adopt_lock);
74 std::lock_guard<std::mutex> lock_other(other.m_mutex, std::adopt_lock);
75 m_queue.swap(other.m_queue);
82 std::lock_guard<std::mutex> lock(m_mutex);
83 return m_queue.size();
90 std::lock_guard<std::mutex> lock(m_mutex);
99 std::lock_guard<std::mutex> lock(m_mutex);
100 m_queue.push(std::move(val));
101 m_ready.notify_one();
108 std::unique_lock<std::mutex> lock(m_mutex);
109 m_ready.wait(lock, [
this] {
return !m_queue.empty(); });
110 val = std::move(m_queue.front());
118 std::unique_lock<std::mutex> lock(m_mutex);
121 val = std::move(m_queue.front());
130 std::lock_guard<std::mutex> lock(m_mutex);