monitor_queue.hpp
Go to the documentation of this file.
00001 //http://www.paulbridger.com/monitor_object/#ixzz2CeN1rr4P
00002 
00003 #ifndef PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_
00004 #define PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_
00005 
00006 #include <queue>
00007 
00008 template<typename DataT>
00009 class MonitorQueue : boost::noncopyable
00010 {
00011 public:
00012   void
00013   push (const DataT& newData)
00014   {
00015     boost::mutex::scoped_lock lock (monitor_mutex_);
00016     queue_.push (newData);
00017     item_available_.notify_one ();
00018   }
00019 
00020   DataT
00021   pop ()
00022   {
00023     boost::mutex::scoped_lock lock (monitor_mutex_);
00024 
00025     if (queue_.empty ())
00026     {
00027       item_available_.wait (lock);
00028     }
00029 
00030     DataT temp (queue_.front ());
00031     queue_.pop ();
00032 
00033     return temp;
00034   }
00035 
00036 private:
00037   std::queue<DataT> queue_;
00038   boost::mutex monitor_mutex_;
00039   boost::condition item_available_;
00040 };
00041 
00042 #endif //PCL_OUTOFCORE_MONITOR_QUEUE_IMPL_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:40