HLR  0.0.1
ConcurrentQueue.hpp
1 #ifndef KINEMATICS_CONCURRENTQUEUE_HPP
2 #define KINEMATICS_CONCURRENTQUEUE_HPP
3 
4 #include <condition_variable>
5 #include <mutex>
6 #include <queue>
7 
8 namespace HLR
9 {
10 namespace Kinematics
11 {
17 template<class T>
19 {
20 public:
26  void push(const T& element);
27 
33  void push(T&& element);
34 
41  T pop();
42 
49  void async_pop(const std::function<void(const T&)>& handler);
50 
57  bool empty() const;
58 
64  std::size_t size() const;
65 
66 private:
71  std::function<void(const T&)> handler;
72 
76  std::queue<T> queue;
77 
81  mutable std::mutex queue_mutex;
82 
86  std::condition_variable notifier;
87 };
88 
89 } // namespace Kinematics
90 } // namespace HLR
91 
92 #include "ConcurrentQueue.ipp"
93 
94 #endif
T pop()
Remove the oldest element from the queue. Blocks if no element is available.
bool empty() const
Check whether the queue is empty.
A thread safe queue that supports both synchronous pop and asynchronous pop. It&#39;s not allowed to use ...
Definition: ConcurrentQueue.hpp:18
void async_pop(const std::function< void(const T &)> &handler)
Asynchronously pop an element from the queue.
std::size_t size() const
Return how many elements are currently in the queue.
void push(const T &element)
Pushes element into the queue.