libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
Generic resource pool.

Data Structures

struct  CMUTIL_Pool
 Resource pool object. More...
 

Typedefs

typedef void *(* CMPoolItemCreateCB) (void *udata)
 Callback type for creating a pool item.
 
typedef void(* CMPoolItemFreeCB) (void *resource, void *udata)
 Callback type for freeing a pool item.
 
typedef CMBool(* CMPoolItemTestCB) (void *resource, void *udata)
 Callback type for testing a pool item.
 

Functions

CMUTIL_PoolCMUTIL_PoolCreate (int initcnt, int maxcnt, CMPoolItemCreateCB createproc, CMPoolItemFreeCB destroyproc, CMPoolItemTestCB testproc, long pinginterval, CMBool testonborrow, void *udata, CMUTIL_Timer *timer)
 Create a resource pool with specified parameters.
 

Detailed Description

Function Documentation

◆ CMUTIL_PoolCreate()

CMUTIL_Pool * CMUTIL_PoolCreate ( int  initcnt,
int  maxcnt,
CMPoolItemCreateCB  createproc,
CMPoolItemFreeCB  destroyproc,
CMPoolItemTestCB  testproc,
long  pinginterval,
CMBool  testonborrow,
void *  udata,
CMUTIL_Timer timer 
)

Create a resource pool with specified parameters.

Parameters
initcntThe initial number of resources in the pool.
maxcntThe maximum number of resources allowed in the pool.
createprocA callback function to create new resources, or NULL for a pool that never creates resources on its own. Such a pool hands out only what was put into it with AddResource, and CheckOut returns NULL once it runs empty.
destroyprocA callback function to free resources, or NULL if the resources need no cleanup.
testprocA callback function to test the validity of resources, or NULL to treat every resource as valid.
pingintervalThe interval in milliseconds to ping resources for validity.
testonborrowWhether to test resources when they are checked out.
udataUser-defined data to be passed to callback functions.
timerA timer object for scheduling resource pings. Ownership of the timer object is not transferred to the pool. If NULL, creates an internal default timer.
Returns
A pointer to the newly created resource pool, or NULL on failure.