Point Cloud Library (PCL)  1.14.1-dev
monitor_queue.hpp
1 //http://www.paulbridger.com/monitor_object/#ixzz2CeN1rr4P
2 
3 #ifndef PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_
4 #define PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_
5 
6 #include <condition_variable>
7 #include <mutex>
8 #include <queue>
9 
10 template<typename DataT>
11 class MonitorQueue : boost::noncopyable
12 {
13 public:
14  void
15  push (const DataT& newData)
16  {
17  std::lock_guard<std::mutex> lock (monitor_mutex_);
18  queue_.push (newData);
19  item_available_.notify_one ();
20  }
21 
22  DataT
23  pop ()
24  {
25  std::unique_lock<std::mutex> lock (monitor_mutex_);
26 
27  if (queue_.empty ())
28  {
29  item_available_.wait (lock);
30  }
31 
32  DataT temp (queue_.front ());
33  queue_.pop ();
34 
35  return temp;
36  }
37 
38 private:
39  std::queue<DataT> queue_;
40  std::mutex monitor_mutex_;
41  std::condition_variable item_available_;
42 };
43 
44 #endif //PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_
void push(const DataT &newData)