dmlite
0.6
|
Implements a pool of whichever resource. More...
#include <poolcontainer.h>
Public Member Functions | |
PoolContainer (PoolElementFactory< E > *factory, int n) | |
~PoolContainer () | |
Destructor. | |
E | acquire (bool block=true) |
Acquires a free resource. | |
E | acquire (E e) |
Increases the reference count of a resource. | |
unsigned | release (E e) |
unsigned | refCount (E e) |
Count the number of instances. | |
void | resize (int ns) |
Private Attributes | |
int | max_ |
PoolElementFactory< E > * | factory_ |
std::queue< E > | free_ |
std::map< E, unsigned > | used_ |
unsigned | freeSlots_ |
boost::mutex | mutex_ |
boost::condition_variable | available_ |
Implements a pool of whichever resource.
dmlite::PoolContainer< E >::PoolContainer | ( | PoolElementFactory< E > * | factory, |
int | n | ||
) | [inline] |
Constructor
factory | The factory to use when spawning a new resource. |
n | The number of resources to keep. |
dmlite::PoolContainer< E >::~PoolContainer | ( | ) | [inline] |
Destructor.
E dmlite::PoolContainer< E >::acquire | ( | bool | block = true | ) | [inline] |
Acquires a free resource.
E dmlite::PoolContainer< E >::acquire | ( | E | e | ) | [inline] |
Increases the reference count of a resource.
unsigned dmlite::PoolContainer< E >::refCount | ( | E | e | ) | [inline] |
Count the number of instances.
unsigned dmlite::PoolContainer< E >::release | ( | E | e | ) | [inline] |
Releases a resource
e | The resource to release. |
void dmlite::PoolContainer< E >::resize | ( | int | ns | ) | [inline] |
Change the pool size
ns | The new size. |
boost::condition_variable dmlite::PoolContainer< E >::available_ [private] |
PoolElementFactory<E>* dmlite::PoolContainer< E >::factory_ [private] |
std::queue<E> dmlite::PoolContainer< E >::free_ [private] |
unsigned dmlite::PoolContainer< E >::freeSlots_ [private] |
int dmlite::PoolContainer< E >::max_ [private] |
boost::mutex dmlite::PoolContainer< E >::mutex_ [private] |
std::map<E, unsigned> dmlite::PoolContainer< E >::used_ [private] |