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> 28 # include <hpp/pinocchio/config.hh> 48 class HPP_PINOCCHIO_DLLAPI
Pool 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 ~Pool()
Definition: pool.hh:117
void release(T *t)
Definition: pool.hh:66
Pool of objects.
Definition: pool.hh:48
void push_back(T *t)
Definition: pool.hh:100
bool available() const
Returns true is at least one object is not locked.
Definition: pool.hh:78
T * acquire()
Definition: pool.hh:53
Pool()
Constructor.
Definition: pool.hh:123
void clear()
Deletes all internal objects.
Definition: pool.hh:89
std::size_t size() const
Definition: pool.hh:83
void push_back(InputIterator first, InputIterator last)
Definition: pool.hh:109