17 #ifndef CYBER_BASE_THREAD_SAFE_QUEUE_H_ 18 #define CYBER_BASE_THREAD_SAFE_QUEUE_H_ 20 #include <condition_variable> 40 std::lock_guard<std::mutex> lock(mutex_);
41 queue_.emplace(element);
46 std::lock_guard<std::mutex> lock(mutex_);
50 *element = std::move(queue_.front());
56 std::unique_lock<std::mutex> lock(mutex_);
57 cv_.wait(lock, [
this]() {
return break_all_wait_ || !queue_.empty(); });
58 if (break_all_wait_) {
61 *element = std::move(queue_.front());
66 typename std::queue<T>::size_type
Size() {
67 std::lock_guard<std::mutex> lock(mutex_);
72 std::lock_guard<std::mutex> lock(mutex_);
73 return queue_.empty();
77 break_all_wait_ =
true;
82 volatile bool break_all_wait_ =
false;
85 std::condition_variable cv_;
92 #endif // CYBER_BASE_THREAD_SAFE_QUEUE_H_ ThreadSafeQueue()
Definition: thread_safe_queue.h:33
~ThreadSafeQueue()
Definition: thread_safe_queue.h:37
std::queue< T >::size_type Size()
Definition: thread_safe_queue.h:66
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool WaitDequeue(T *element)
Definition: thread_safe_queue.h:55
void Enqueue(const T &element)
Definition: thread_safe_queue.h:39
bool Empty()
Definition: thread_safe_queue.h:71
bool Dequeue(T *element)
Definition: thread_safe_queue.h:45
Definition: thread_safe_queue.h:31
void BreakAllWait()
Definition: thread_safe_queue.h:76
ThreadSafeQueue & operator=(const ThreadSafeQueue &other)=delete