00001 #ifndef toast_async_locking_queue_hpp_INCLUDED
00002 #define toast_async_locking_queue_hpp_INCLUDED
00003
00004 #include <list>
00005 #include <boost/thread/mutex.hpp>
00006
00007 namespace toast {
00008 namespace async {
00009
00023 template <typename T>
00024 class locking_queue
00025 {
00026 std::list<T> list_;
00027 boost::mutex mutex_;
00028 public:
00035 void push(std::list<T> &l)
00036 {
00037 boost::mutex::scoped_lock lock(mutex_);
00038 list_.splice(list_.end(), l);
00039 }
00040
00042 void push(T const &t)
00043 {
00044 std::list<T> temp(1, t);
00045 push(temp);
00046 }
00047
00059 void pop_one(std::list<T> &l)
00060 {
00061 boost::mutex::scoped_lock lock(mutex_);
00062 if(!list_.empty())
00063 l.splice(l.end(), list_, list_.begin());
00064 }
00065
00073 void pop(std::list<T> &l)
00074 {
00075 boost::mutex::scoped_lock lock(mutex_);
00076 l.splice(l.end(), list_);
00077 }
00078 };
00079
00082 }
00083 }
00084
00085 #endif // toast_async_locking_queue_hpp_INCLUDED