Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
lockfree::ObjectPool< T > Class Template Reference

A fixed-count lock-free pool of the same type of object. Supports both bare- and shared-pointer allocation. More...

#include <object_pool.h>

Classes

struct  Deleter
 

Public Member Functions

T * allocate ()
 Allocate a single object from the pool, returning a bare pointer. More...
 
boost::shared_ptr< T > allocateShared ()
 Allocate a single object from the pool, returning a shared pointer. More...
 
void free (T const *t)
 Return an object allocated through allocateBare() to the pool. More...
 
bool hasOutstandingAllocations ()
 Returns whether or not this ObjectPool has any outstanding allocations. More...
 
void initialize (uint32_t count, const T &tmpl)
 initialize the pool. Only use with the default constructor More...
 
boost::shared_ptr< T > makeShared (T *t)
 Make a shared_ptr out of a bare pointer allocated by this pool. More...
 
boost::shared_ptr< T const > makeShared (T const *t)
 Make a shared_ptr out of a bare pointer allocated by this pool. More...
 
 ObjectPool ()
 Default constructor. Must call initialize() before calling allocate() More...
 
 ObjectPool (uint32_t count, const T &tmpl)
 Constructor with initialization. More...
 
bool owns (const boost::shared_ptr< T const > &t)
 Returns whether or not this pool owns the provided object. More...
 
bool owns (T const *t)
 Returns whether or not this pool owns the provided object. More...
 
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 this object will no longer delete the object when the go out of scope. Generally dangerous and not to be used lightly, this will probably go away in the future. More...
 
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 this object will no longer delete the object when the go out of scope. Generally dangerous and not to be used lightly, this will probably go away in the future. More...
 
 ~ObjectPool ()
 

Private Member Functions

template<typename T2 >
boost::shared_ptr< T2 > makeSharedImpl (T2 *t)
 

Private Attributes

FreeList freelist_
 
bool initialized_
 
FreeList sp_storage_freelist_
 

Detailed Description

template<typename T>
class lockfree::ObjectPool< T >

A fixed-count lock-free pool of the same type of object. Supports both bare- and shared-pointer allocation.

Parameters
Tthe object type

Definition at line 80 of file object_pool.h.

Constructor & Destructor Documentation

◆ ObjectPool() [1/2]

template<typename T >
lockfree::ObjectPool< T >::ObjectPool ( )
inline

Default constructor. Must call initialize() before calling allocate()

Definition at line 260 of file object_pool.h.

◆ ObjectPool() [2/2]

template<typename T >
lockfree::ObjectPool< T >::ObjectPool ( uint32_t  count,
const T &  tmpl 
)
inline

Constructor with initialization.

Parameters
countThe number of objects in the pool
tmplThe object template to use to construct the objects

Definition at line 270 of file object_pool.h.

◆ ~ObjectPool()

template<typename T >
lockfree::ObjectPool< T >::~ObjectPool ( )
inline

Definition at line 276 of file object_pool.h.

Member Function Documentation

◆ allocate()

template<typename T >
T* lockfree::ObjectPool< T >::allocate ( )
inline

Allocate a single object from the pool, returning a bare pointer.

Returns
0 if there are no objects left in the pool. Otherwise a pointer to an object of type T

Definition at line 379 of file object_pool.h.

◆ allocateShared()

template<typename T >
boost::shared_ptr<T> lockfree::ObjectPool< T >::allocateShared ( )
inline

Allocate a single object from the pool, returning a shared pointer.

Returns
An empty shared pointer if there are no objects left in the pool. Otherwise a shared pointer to an object of type T

Definition at line 310 of file object_pool.h.

◆ free()

template<typename T >
void lockfree::ObjectPool< T >::free ( T const *  t)
inline

Return an object allocated through allocateBare() to the pool.

Parameters
tAn object that was allocated with allocateBare()

Definition at line 388 of file object_pool.h.

◆ hasOutstandingAllocations()

template<typename T >
bool lockfree::ObjectPool< T >::hasOutstandingAllocations ( )
inline

Returns whether or not this ObjectPool has any outstanding allocations.

Definition at line 285 of file object_pool.h.

◆ initialize()

template<typename T >
void lockfree::ObjectPool< T >::initialize ( uint32_t  count,
const T &  tmpl 
)
inline

initialize the pool. Only use with the default constructor

Parameters
countThe number of objects in the pool
tmplThe object template to use to construct the objects

Definition at line 295 of file object_pool.h.

◆ makeShared() [1/2]

template<typename T >
boost::shared_ptr<T> lockfree::ObjectPool< T >::makeShared ( T *  t)
inline

Make a shared_ptr out of a bare pointer allocated by this pool.

Definition at line 333 of file object_pool.h.

◆ makeShared() [2/2]

template<typename T >
boost::shared_ptr<T const> lockfree::ObjectPool< T >::makeShared ( T const *  t)
inline

Make a shared_ptr out of a bare pointer allocated by this pool.

Definition at line 341 of file object_pool.h.

◆ makeSharedImpl()

template<typename T >
template<typename T2 >
boost::shared_ptr<T2> lockfree::ObjectPool< T >::makeSharedImpl ( T2 *  t)
inlineprivate

Definition at line 412 of file object_pool.h.

◆ owns() [1/2]

template<typename T >
bool lockfree::ObjectPool< T >::owns ( const boost::shared_ptr< T const > &  t)
inline

Returns whether or not this pool owns the provided object.

Definition at line 404 of file object_pool.h.

◆ owns() [2/2]

template<typename T >
bool lockfree::ObjectPool< T >::owns ( T const *  t)
inline

Returns whether or not this pool owns the provided object.

Definition at line 396 of file object_pool.h.

◆ removeShared() [1/2]

template<typename T >
T* lockfree::ObjectPool< T >::removeShared ( const boost::shared_ptr< T > &  t)
inline

"Remove" a shared pointer allocated by this pool, turning it into a bare pointer. shared_ptrs held to this object will no longer delete the object when the go out of scope. Generally dangerous and not to be used lightly, this will probably go away in the future.

Definition at line 351 of file object_pool.h.

◆ removeShared() [2/2]

template<typename T >
T const* lockfree::ObjectPool< T >::removeShared ( const boost::shared_ptr< T const > &  t)
inline

"Remove" a shared pointer allocated by this pool, turning it into a bare pointer. shared_ptrs held to this object will no longer delete the object when the go out of scope. Generally dangerous and not to be used lightly, this will probably go away in the future.

Definition at line 365 of file object_pool.h.

Member Data Documentation

◆ freelist_

template<typename T >
FreeList lockfree::ObjectPool< T >::freelist_
private

Definition at line 429 of file object_pool.h.

◆ initialized_

template<typename T >
bool lockfree::ObjectPool< T >::initialized_
private

Definition at line 427 of file object_pool.h.

◆ sp_storage_freelist_

template<typename T >
FreeList lockfree::ObjectPool< T >::sp_storage_freelist_
private

Definition at line 430 of file object_pool.h.


The documentation for this class was generated from the following file:


lockfree
Author(s): Josh Faust
autogenerated on Thu May 20 2021 02:25:30