include/mpool.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MPOOL_POISON   1
#define MPOOL_POISON_PATTERN   0xa5

Typedefs

typedef struct _mpoolmpool_t

Functions

_private mpool_t mpool_new (size_t obj_size, unsigned slab_size)
 Initialise an mpool.
_private void mpool_free (mpool_t m)
 Destroy an mpool object.
_private void * mpool_alloc (mpool_t m) _malloc
 Allocate an object from an mpool.
_private void * mpool_alloc0 (mpool_t m) _malloc
 Allocate an object initialized to zero.
_private void mpool_return (mpool_t m, void *obj)
 Free an individual object.

Define Documentation

#define MPOOL_POISON   1

Definition at line 11 of file mpool.h.

#define MPOOL_POISON_PATTERN   0xa5

Definition at line 12 of file mpool.h.


Typedef Documentation

typedef struct _mpool* mpool_t

Definition at line 9 of file mpool.h.


Function Documentation

_private void* mpool_alloc ( mpool_t  m  ) 

Allocate an object from an mpool.

Parameters:
m a valid mpool structure returned from mpool_init()

Allocate a new object, returns NULL if out of memory. This is the fast path. It never calls malloc directly.

Returns:
a new object

Definition at line 136 of file mpool.c.

References _mpool::free, mpool_alloc_slow(), _mpool_hdr::next_obj, _mpool::obj_size, _mpool::slab_size, _mpool::slabs, and unlikely.

Referenced by composite(), decode_record(), and mpool_alloc0().

Here is the call graph for this function:

Here is the caller graph for this function:

_private void* mpool_alloc0 ( mpool_t  m  ) 

Allocate an object initialized to zero.

Parameters:
m mpool object to allocate from.

This is the same as mpool_alloc() but initializes the returned memory to all zeros.

Returns:
pointer to new object or NULL for error

Definition at line 211 of file mpool.c.

References mpool_alloc(), and _mpool::obj_size.

Here is the call graph for this function:

_private void mpool_free ( mpool_t  m  ) 

Destroy an mpool object.

Parameters:
m a valid mpool structure returned from mpool_init()

Frees up all allocated memory from the mpool and resets all members to invalid values.

Definition at line 165 of file mpool.c.

References _mpool_hdr::next, POISON, _mpool::slab_size, and _mpool::slabs.

Referenced by do_emv_fini(), emv_init(), and emv_read_app_data().

Here is the caller graph for this function:

_private mpool_t mpool_new ( size_t  obj_size,
unsigned  slab_size 
)

Initialise an mpool.

Parameters:
m an mpool structure to use
obj_size size of objects to allocate
slab_size size of slabs in number of objects (set to zero for auto)

Creates a new empty memory pool descriptor with the passed values set. The resultant mpool has no alignment requirement set.

Returns:
zero on error, non-zero for success (may only return 0 if the obj_size is 0).

Definition at line 58 of file mpool.c.

References _mpool::free, _mpool::obj_size, _mpool::slab_size, and _mpool::slabs.

Referenced by emv_init(), and emv_read_app_data().

Here is the caller graph for this function:

_private void mpool_return ( mpool_t  m,
void *  obj 
)

Free an individual object.

Parameters:
m mpool object that obj was allocated from.
obj pointer to object to free.

When an mpool object is free'd it's added to a linked list of free objects which mpool_alloc() scans before trying to commit further memory resources.

Definition at line 190 of file mpool.c.

References _mpool::free, _mpool::obj_size, POISON, and unlikely.

Generated on Sun Jan 2 08:34:46 2011 for ccid-utils by  doxygen 1.6.3