dmlite  0.6
Public Member Functions | Private Attributes | List of all members
dmlite::PoolContainer< E > Class Template Reference

Implements a pool of whichever resource. More...

#include <poolcontainer.h>

Public Member Functions

 PoolContainer (PoolElementFactory< E > *factory, int n)
 
 ~PoolContainer ()
 Destructor. More...
 
acquire (bool block=true)
 Acquires a free resource. More...
 
acquire (E e)
 Increases the reference count of a resource. More...
 
unsigned release (E e)
 
unsigned refCount (E e)
 Count the number of instances. More...
 
void resize (int ns)
 

Private Attributes

int max_
 
PoolElementFactory< E > * factory_
 
std::deque< E > free_
 
std::map< E, unsigned > used_
 
int freeSlots_
 
boost::mutex mutex_
 
boost::condition_variable available_
 

Detailed Description

template<class E>
class dmlite::PoolContainer< E >

Implements a pool of whichever resource.

Constructor & Destructor Documentation

template<class E>
dmlite::PoolContainer< E >::PoolContainer ( PoolElementFactory< E > *  factory,
int  n 
)
inline

Constructor

Parameters
factoryThe factory to use when spawning a new resource.
nThe number of resources to keep in the pool. Up to 10*n slots can be created without penalty (but only n will be pooled)
template<class E>
dmlite::PoolContainer< E >::~PoolContainer ( )
inline

Destructor.

Member Function Documentation

template<class E>
E dmlite::PoolContainer< E >::acquire ( bool  block = true)
inline

Acquires a free resource.

template<class E>
E dmlite::PoolContainer< E >::acquire ( e)
inline

Increases the reference count of a resource.

template<class E>
unsigned dmlite::PoolContainer< E >::refCount ( e)
inline

Count the number of instances.

template<class E>
unsigned dmlite::PoolContainer< E >::release ( e)
inline

Releases a resource

Parameters
eThe resource to release.
Returns
The reference count after releasing.
template<class E>
void dmlite::PoolContainer< E >::resize ( int  ns)
inline

Change the pool size

Parameters
nsThe new size.

Member Data Documentation

template<class E>
boost::condition_variable dmlite::PoolContainer< E >::available_
private
template<class E>
PoolElementFactory<E>* dmlite::PoolContainer< E >::factory_
private
template<class E>
std::deque<E> dmlite::PoolContainer< E >::free_
private
template<class E>
int dmlite::PoolContainer< E >::freeSlots_
private
template<class E>
int dmlite::PoolContainer< E >::max_
private
template<class E>
boost::mutex dmlite::PoolContainer< E >::mutex_
private
template<class E>
std::map<E, unsigned> dmlite::PoolContainer< E >::used_
private

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