Point Cloud Library (PCL)  1.8.1
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 <queue>
7 
8 template<typename DataT>
9 class MonitorQueue : boost::noncopyable
10 {
11 public:
12  void
13  push (const DataT& newData)
14  {
15  boost::mutex::scoped_lock lock (monitor_mutex_);
16  queue_.push (newData);
17  item_available_.notify_one ();
18  }
19 
20  DataT
21  pop ()
22  {
23  boost::mutex::scoped_lock lock (monitor_mutex_);
24 
25  if (queue_.empty ())
26  {
27  item_available_.wait (lock);
28  }
29 
30  DataT temp (queue_.front ());
31  queue_.pop ();
32 
33  return temp;
34  }
35 
36 private:
37  std::queue<DataT> queue_;
38  boost::mutex monitor_mutex_;
39  boost::condition item_available_;
40 };
41 
42 #endif //PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_
void push(const DataT &newData)