1 #ifndef SIM_OBJECTPOOL_HH
2 #define SIM_OBJECTPOOL_HH
5 #include <boost/noncopyable.hpp>
6 #include <boost/thread/mutex.hpp>
25 std::list<T*> m_available;
27 typedef boost::mutex mutex;
31 {
sweep(m_available.begin(), m_available.end()); }
34 { mutex::scoped_lock lock(m_mutex);
35 if (m_available.empty())
36 m_available.push_back(
new T());
38 T* ret = m_available.front();
39 m_available.pop_front();
44 { mutex::scoped_lock lock(m_mutex);
45 m_available.push_back(
object);
53 class use : boost::noncopyable
60 : m_pool(pool), m_object(pool.
get()) {}
61 ~use() { m_pool.put(m_object); }
T & operator*()
Definition: objectpool.hh:65
Definition: objectpool.hh:53
~use()
Definition: objectpool.hh:61
void sweep(Iterator begin, Iterator end)
Definition: sweep.hh:9
T * operator->()
Definition: objectpool.hh:63
~object_pool()
Definition: objectpool.hh:30
use(object_pool< T > &pool)
Definition: objectpool.hh:59
Definition: objectpool.hh:22
boost::property_traits< PropertyMap >::value_type get(undirected_property_map< PropertyMap > const &map, EdgeDescriptor e)
Definition: undirected_graph.hh:333
void put(T *object)
Definition: objectpool.hh:43