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_ |
| pthread_mutex_t | mutex_ |
| sem_t | 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 | ( | E | e | ) | [inline] |
Increases the reference count of a resource.
| E dmlite::PoolContainer< E >::acquire | ( | bool | block = true |
) | [inline] |
Acquires a free 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. |
sem_t dmlite::PoolContainer< E >::available_ [private] |
PoolElementFactory<E>* dmlite::PoolContainer< E >::factory_ [private] |
std::queue<E> dmlite::PoolContainer< E >::free_ [private] |
int dmlite::PoolContainer< E >::max_ [private] |
pthread_mutex_t dmlite::PoolContainer< E >::mutex_ [private] |
std::map<E, unsigned> dmlite::PoolContainer< E >::used_ [private] |
1.6.1