1 #ifndef teca_threadsafe_queue_h
2 #define teca_threadsafe_queue_h
6 #include <condition_variable>
17 typename std::queue<T>::size_type size()
const;
20 void push(
const T &val);
37 mutable std::mutex m_mutex;
38 std::queue<T> m_queue;
39 std::condition_variable m_ready;
40 std::condition_variable m_empty;
48 std::lock_guard<std::mutex> lock(other.m_mutex);
49 std::queue<T> tmp(other.m_queue);
58 std::lock(m_mutex, other.m_mutex);
59 std::lock_guard<std::mutex> lock(m_mutex, std::adopt_lock);
60 std::lock_guard<std::mutex> lock_other(other.m_mutex, std::adopt_lock);
61 std::queue<T> tmp(other.m_queue);
69 std::lock(m_mutex, other.m_mutex);
70 std::lock_guard<std::mutex> lock(m_mutex, std::adopt_lock);
71 std::lock_guard<std::mutex> lock_other(other.m_mutex, std::adopt_lock);
72 m_queue.swap(other.m_queue);
79 std::lock_guard<std::mutex> lock(m_mutex);
80 return m_queue.size();
87 std::lock_guard<std::mutex> lock(m_mutex);
96 std::lock_guard<std::mutex> lock(m_mutex);
97 m_queue.push(std::move(val));
105 std::unique_lock<std::mutex> lock(m_mutex);
106 m_ready.wait(lock, [
this] {
return !m_queue.empty(); });
107 val = std::move(m_queue.front());
115 std::unique_lock<std::mutex> lock(m_mutex);
118 val = std::move(m_queue.front());
127 std::lock_guard<std::mutex> lock(m_mutex);