35 #ifndef LOCKFREE_OBJECT_POOL_H 36 #define LOCKFREE_OBJECT_POOL_H 42 #include <boost/shared_ptr.hpp> 86 block_ = u.get_block();
129 block_ = u.get_block();
130 used_ = u.get_used();
131 pool_ = u.get_pool();
142 const_pointer
address(const_reference r)
const 148 return ~size_type(0);
152 uint32_t to_alloc = n *
sizeof(T);
155 pointer p =
reinterpret_cast<pointer
>(block_->data + used_);
161 uint32_t to_free = n *
sizeof(T);
165 if (used_ == 0 || used_ < 0)
229 : initialized_(false)
239 : initialized_(false)
246 freelist_.template destructAll<T>();
247 sp_storage_freelist_.template destructAll<detail::SPStorage>();
255 return freelist_.hasOutstandingAllocations() || sp_storage_freelist_.hasOutstandingAllocations();
266 freelist_.initialize(
sizeof(T), count);
267 freelist_.template constructAll<T>(tmpl);
269 sp_storage_freelist_.template constructAll<detail::SPStorage>();
282 T* item =
static_cast<T*
>(freelist_.allocate());
291 freelist_.free(item);
303 return makeSharedImpl(t);
311 return makeSharedImpl<T const>(t);
323 Deleter*
d = boost::get_deleter<Deleter>(t);
337 Deleter*
d = boost::get_deleter<Deleter>(t);
349 return static_cast<T*
>(freelist_.allocate());
366 return freelist_.owns(t);
374 return owns(t.get());
379 template<
typename T2>
403 #endif // LOCKFREE_OBJECT_POOL_H SPStorage * get_block() const
A fixed-count lock-free pool of the same type of object. Supports both bare- and shared-pointer alloc...
boost::shared_ptr< T > allocateShared()
Allocate a single object from the pool, returning a shared pointer.
SPAllocator(const SPAllocator< U > &u)
void deallocate(pointer p, size_type n)
boost::shared_ptr< T > makeShared(T *t)
Make a shared_ptr out of a bare pointer allocated by this pool.
pointer allocate(size_type n, SPAllocator< void >::const_pointer hint=0)
uint32_t get_used() const
ROSCONSOLE_DECL void initialize()
ObjectPool(uint32_t count, const T &tmpl)
Constructor with initialization.
size_type max_size() const
bool owns(T const *t)
Returns whether or not this pool owns the provided object.
void initialize(uint32_t count, const T &tmpl)
initialize the pool. Only use with the default constructor
void free(T const *t)
Return an object allocated through allocateBare() to the pool.
ptrdiff_t difference_type
pointer address(reference r) const
FreeList * get_pool() const
bool owns(const boost::shared_ptr< T const > &t)
Returns whether or not this pool owns the provided object.
SPStorage * get_block() const
const void * const_pointer
#define ROS_ASSERT_MSG(cond,...)
ObjectPool()
Default constructor. Must call initialize() before calling allocate()
Deleter(ObjectPool *pool, detail::SPStorage *storage)
FreeList sp_storage_freelist_
bool hasOutstandingAllocations()
Returns whether or not this ObjectPool has any outstanding allocations.
boost::shared_ptr< T2 > makeSharedImpl(T2 *t)
SPAllocator(FreeList *pool, SPStorage *block)
T * removeShared(const boost::shared_ptr< T > &t)
"Remove" a shared pointer allocated by this pool, turning it into a bare pointer. shared_ptrs held to...
FreeList * get_pool() const
void construct(pointer p, const_reference val)
SPAllocator(const SPAllocator< U > &u)
const T & const_reference
T * allocate()
Allocate a single object from the pool, returning a bare pointer.
A lock-free (not wait-free) statically-sized free-list implemented with CAS.
boost::shared_ptr< T const > makeShared(T const *t)
Make a shared_ptr out of a bare pointer allocated by this pool.
const_pointer address(const_reference r) const
T const * removeShared(const boost::shared_ptr< T const > &t)
"Remove" a shared pointer allocated by this pool, turning it into a bare pointer. shared_ptrs held to...
SPAllocator(FreeList *pool, SPStorage *block)
void operator()(T const *t)