20 #ifndef HPP_PINOCCHIO_POOL_HH
21 #define HPP_PINOCCHIO_POOL_HH
25 # include <boost/thread/mutex.hpp>
26 # include <boost/thread/condition_variable.hpp>
55 boost::mutex::scoped_lock lock (mutex_);
56 condVariable_.wait (lock, OneIsAvailable(*
this));
58 std::swap (ret, Ts_[lastFree_]);
68 boost::mutex::scoped_lock lock (mutex_);
70 assert (lastFree_ > 0);
71 assert (Ts_[lastFree_-1] == NULL);
74 condVariable_.notify_one ();
80 return OneIsAvailable (*
this) ();
91 boost::mutex::scoped_lock lock (mutex_);
93 throw std::logic_error (
"Cannot free pool when some objects are in use.");
94 for (std::size_t i = 0; i < size(); ++i)
delete Ts_[i];
102 boost::mutex::scoped_lock lock (mutex_);
108 template <
class InputIterator>
109 void push_back (InputIterator first, InputIterator last)
111 boost::mutex::scoped_lock lock (mutex_);
112 Ts_.insert(Ts_.end(), first, last);
126 struct OneIsAvailable
129 OneIsAvailable (
const Pool& pool) : p (pool) {}
130 bool operator() () {
return p.lastFree_ < p.
size(); }
134 boost::condition_variable condVariable_;
136 std::size_t lastFree_;
141 #endif // HPP_PINOCCHIO_DEVICE_HH