Rudiments
Public Member Functions | List of all members
resourcepool< valuetype > Class Template Reference

#include <resourcepool.h>

Public Member Functions

 resourcepool ()
 
virtual ~resourcepool ()
 
void setMin (uint64_t min)
 
uint64_t getMin ()
 
void setMax (uint64_t max)
 
uint64_t getMax ()
 
void setGrowBy (uint64_t growby)
 
uint64_t getGrowBy ()
 
bool create ()
 
bool clear ()
 
bool reset ()
 
valuetypeborrowResource ()
 
bool returnResource (valuetype *resource)
 
void setMutex (threadmutex *mtx)
 
uint64_t getAvailableInitialResourceCount ()
 
uint64_t getAvailableOnDemandResourceCount ()
 

Detailed Description

template<class valuetype>
class resourcepool< valuetype >

The resourcepool class provides a pool of objects. Objects can be borrowed from and returned to the pool. The pool contains a configurable number of objects that are allocated when the pool is initialized, and can allocate a configurable number of additional objects on-demand.

Constructor & Destructor Documentation

◆ resourcepool()

Creates an empty instance of the resourcepool class.

◆ ~resourcepool()

template<class valuetype >
resourcepool< valuetype >::~resourcepool ( )
inlinevirtual

Deletes this instance of the resourcepool class and all resources in the pool.

Member Function Documentation

◆ borrowResource()

template<class valuetype >
valuetype * resourcepool< valuetype >::borrowResource ( )
inline

Returns a pointer to an instance of "valuetype" from the pool, or NULL if none are available or a mutex lock failed.

◆ clear()

template<class valuetype >
bool resourcepool< valuetype >::clear ( )
inline

Clears the resourcepool, deleting all resources in the pool.

Returns true on success and false if a mutex lock failed.

◆ create()

template<class valuetype >
bool resourcepool< valuetype >::create ( )
inline

Creates a resource pool, containing the number of resources configured by setMin().

Returns true on success and false on failure.

◆ getAvailableInitialResourceCount()

template<class valuetype >
uint64_t resourcepool< valuetype >::getAvailableInitialResourceCount ( )
inline

Returns the number of resources that are available in the pool without creating any resources on-demand.

◆ getAvailableOnDemandResourceCount()

template<class valuetype >
uint64_t resourcepool< valuetype >::getAvailableOnDemandResourceCount ( )
inline

Returns the number of resources that have been created on-demand but have not been loaned out.

◆ getGrowBy()

template<class valuetype >
uint64_t resourcepool< valuetype >::getGrowBy ( )
inline

Returns the number of resources that will be created when the pool grows on-demand.

◆ getMax()

template<class valuetype >
uint64_t resourcepool< valuetype >::getMax ( )
inline

Returns the number of resources that the pool can grow to on-demand.

◆ getMin()

template<class valuetype >
uint64_t resourcepool< valuetype >::getMin ( )
inline

Returns the number of resources that will be created when the pool is initialized.

◆ reset()

template<class valuetype >
bool resourcepool< valuetype >::reset ( )
inline

Clears the resourcepool, deleting all resources in the pool, and resets min, max, and growby to defaults.

Returns true on success and false if a mutex lock failed.

◆ returnResource()

template<class valuetype >
bool resourcepool< valuetype >::returnResource ( valuetype * resource)
inline

Returns "resource" to the pool.

Returns true on success and false if a mutex lock failed.

◆ setGrowBy()

template<class valuetype >
void resourcepool< valuetype >::setGrowBy ( uint64_t growby)
inline

Sets the number of resources that will be created when the pool grows on-demand.

Defaults to 1.

◆ setMax()

template<class valuetype >
void resourcepool< valuetype >::setMax ( uint64_t max)
inline

Sets the maximum number of resources that the pool can grow to on-demand.

Defaults to 10.

◆ setMin()

template<class valuetype >
void resourcepool< valuetype >::setMin ( uint64_t min)
inline

Sets the number of resources that will be created when the pool is initialized.

Defaults to 0.

◆ setMutex()

template<class valuetype >
void resourcepool< valuetype >::setMutex ( threadmutex * mtx)
inline

Sets a mutex to use when borrowing or returning resources. To not use a mutex set "mtx" to NULL. Defaults to NULL.