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()) {}
63 T* operator -> () {
return m_object; }
64 T
const* operator ->()
const {
return m_object; }
65 T& operator *() {
return *m_object; }
66 T
const& operator *()
const {
return *m_object; }
Definition: objectpool.hh:53
~use()
Definition: objectpool.hh:61
T * get()
Definition: objectpool.hh:33
void sweep(Iterator begin, Iterator end)
Definition: sweep.hh:9
Definition: auto_flag.hh:6
~object_pool()
Definition: objectpool.hh:30
use(object_pool< T > &pool)
Definition: objectpool.hh:59
Definition: objectpool.hh:22
void put(T *object)
Definition: objectpool.hh:43