1 #ifndef OSMIUM_THREAD_QUEUE_HPP
2 #define OSMIUM_THREAD_QUEUE_HPP
37 #include <condition_variable>
44 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
76 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
77 std::size_t m_largest_size;
81 std::atomic<int> m_push_counter;
85 std::atomic<int> m_full_counter;
91 std::atomic<int> m_pop_counter;
95 std::atomic<int> m_empty_counter;
107 explicit Queue(std::size_t max_size = 0, std::string name =
"") :
111 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
128 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
130 std::cerr <<
"queue '" <<
m_name
132 <<
" had largest size " << m_largest_size
133 <<
" and was full " << m_full_counter
134 <<
" times in " << m_push_counter
135 <<
" push() calls and was empty " << m_empty_counter
136 <<
" times in " << m_pop_counter
148 constexpr
const std::chrono::milliseconds max_wait{10};
149 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
154 std::unique_lock<std::mutex> lock{
m_mutex};
158 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
163 std::lock_guard<std::mutex> lock{
m_mutex};
164 m_queue.push(std::move(value));
165 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
166 if (m_largest_size <
m_queue.size()) {
167 m_largest_size =
m_queue.size();
174 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
177 std::unique_lock<std::mutex> lock{
m_mutex};
178 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
187 value = std::move(
m_queue.front());
197 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
201 std::lock_guard<std::mutex> lock{
m_mutex};
203 #ifdef OSMIUM_DEBUG_QUEUE_SIZE
208 value = std::move(
m_queue.front());
218 std::lock_guard<std::mutex> lock{
m_mutex};
223 std::lock_guard<std::mutex> lock{
m_mutex};
233 #endif // OSMIUM_THREAD_QUEUE_HPP