17 #ifndef GNSS_SDR_CONCURRENT_QUEUE_H 18 #define GNSS_SDR_CONCURRENT_QUEUE_H 21 #include <condition_variable> 32 template <
typename Data>
44 void push(Data
const& data)
46 std::unique_lock<std::mutex> lock(the_mutex);
49 the_condition_variable.notify_one();
54 std::unique_lock<std::mutex> lock(the_mutex);
55 return the_queue.empty();
60 std::unique_lock<std::mutex> lock(the_mutex);
61 return the_queue.size();
66 std::unique_lock<std::mutex> lock(the_mutex);
67 the_queue = std::queue<Data>();
70 bool try_pop(Data& popped_value)
72 std::unique_lock<std::mutex> lock(the_mutex);
73 if (the_queue.empty())
77 popped_value = the_queue.front();
82 void wait_and_pop(Data& popped_value)
84 std::unique_lock<std::mutex> lock(the_mutex);
85 while (the_queue.empty())
87 the_condition_variable.wait(lock);
89 popped_value = the_queue.front();
93 bool timed_wait_and_pop(Data& popped_value,
int wait_ms)
95 std::unique_lock<std::mutex> lock(the_mutex);
96 if (the_queue.empty())
98 the_condition_variable.wait_for(lock, std::chrono::milliseconds(wait_ms));
99 if (the_queue.empty())
104 popped_value = the_queue.front();
110 std::queue<Data> the_queue;
111 mutable std::mutex the_mutex;
112 std::condition_variable the_condition_variable;
118 #endif // GNSS_SDR_CONCURRENT_QUEUE_H This class implements a thread-safe std::queue.