src/mpool.c File Reference

#include <compiler.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <mpool.h>
Include dependency graph for mpool.c:

Go to the source code of this file.

Data Structures

struct  _mpool
 mpool descriptor. More...
struct  _mpool_hdr
 mpool memory area descriptor. More...

Defines

#define POISON(ptr, len)   do { } while(0);

Functions

mpool_t mpool_new (size_t obj_size, unsigned slab_size)
 Initialise an mpool.
static void * mpool_alloc_slow (struct _mpool *m)
 Slow path for mpool allocations.
void * mpool_alloc (mpool_t m)
 Allocate an object from an mpool.
void mpool_free (mpool_t m)
 Destroy an mpool object.
void mpool_return (mpool_t m, void *obj)
 Free an individual object.
void * mpool_alloc0 (mpool_t m)
 Allocate an object initialized to zero.

Define Documentation

#define POISON ( ptr,
len   )     do { } while(0);

Definition at line 16 of file mpool.c.


Function Documentation

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:

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:

static void* mpool_alloc_slow ( struct _mpool m  )  [static]

Slow path for mpool allocations.

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

Allocate a new object, returns NULL if out of memory. Note that this is the slow path, the fast path for common case (no new allocation needed) is handled in the inline fucntion mpool_alloc() in mpool.h.

Returns:
a new object

Definition at line 105 of file mpool.c.

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

Referenced by mpool_alloc().

Here is the caller graph for this function:

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:

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:

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:35:43 2011 for ccid-utils by  doxygen 1.6.3