1 #ifndef teca_threadsafe_queue_h
2 #define teca_threadsafe_queue_h
6 #include <condition_variable>
18 typename std::queue<T>::size_type size()
const;
21 void push(
const T &val);
38 mutable std::mutex m_mutex;
39 std::queue<T> m_queue;
40 std::condition_variable m_ready;
41 std::condition_variable m_empty;
49 std::lock_guard<std::mutex> lock(other.m_mutex);
50 std::queue<T> tmp(other.m_queue);
59 std::lock(m_mutex, other.m_mutex);
60 std::lock_guard<std::mutex> lock(m_mutex, std::adopt_lock);
61 std::lock_guard<std::mutex> lock_other(other.m_mutex, std::adopt_lock);
62 std::queue<T> tmp(other.m_queue);
70 std::lock(m_mutex, other.m_mutex);
71 std::lock_guard<std::mutex> lock(m_mutex, std::adopt_lock);
72 std::lock_guard<std::mutex> lock_other(other.m_mutex, std::adopt_lock);
73 m_queue.swap(other.m_queue);
80 std::lock_guard<std::mutex> lock(m_mutex);
81 return m_queue.size();
88 std::lock_guard<std::mutex> lock(m_mutex);
97 std::lock_guard<std::mutex> lock(m_mutex);
98 m_queue.push(std::move(val));
106 std::unique_lock<std::mutex> lock(m_mutex);
107 m_ready.wait(lock, [
this] {
return !m_queue.empty(); });
108 val = std::move(m_queue.front());
116 std::unique_lock<std::mutex> lock(m_mutex);
119 val = std::move(m_queue.front());
128 std::lock_guard<std::mutex> lock(m_mutex);