Introduction   API Reference   Examples   Index  

Initialization
[Slab Memory Allocator API]

Slab cache initialization. More...

Typedefs

typedef struct l4slab_cache l4slab_cache_t
 Slab cache descriptor type.
typedef L4_CV void *(* l4slab_grow_fn_t )(l4slab_cache_t *cache, void **data)
 Cache grow callback function.
typedef L4_CV void(* l4slab_release_fn_t )(l4slab_cache_t *cache, void *buffer, void *data)
 Cache release callback function.

Functions

L4_CV int l4slab_cache_init (l4slab_cache_t *cache, l4_size_t size, unsigned int max_free, l4slab_grow_fn_t grow_fn, l4slab_release_fn_t release_fn)
 Initialize slab cache.
L4_CV void l4slab_destroy (l4slab_cache_t *cache)
 Destroy slab cache.
L4_CV void l4slab_add_slab (l4slab_cache_t *cache, void *buffer, void *data)
 Add a slab to the slab cache.
L4_CV void l4slab_set_data (l4slab_cache_t *cache, void *data)
 Set cache application data pointer.
L4_CV void * l4slab_get_data (l4slab_cache_t *cache)
 Get cache application data.

Detailed Description

Slab cache initialization.


Typedef Documentation

typedef struct l4slab_cache l4slab_cache_t

Slab cache descriptor type.

Definition at line 45 of file slab.h.

typedef L4_CV void*(* l4slab_grow_fn_t)(l4slab_cache_t *cache, void **data)

Cache grow callback function.

Parameters:
cache Descriptor of the slab cache which requests the memory
Return values:
data Slab user data pointer, the contents is returned with the slab to the release callback function.
Returns:
Pointer to the allocated slab.
This function is called by a slab cache to allocate a new slab for the cache. It must return a pointer to a memory area with the size of cache->slab_size and which is slab_size aligned.

Definition at line 62 of file slab.h.

typedef L4_CV void(* l4slab_release_fn_t)(l4slab_cache_t *cache, void *buffer, void *data)

Cache release callback function.

Parameters:
cache Slab cache descriptor
buffer Slab address
data Slab user data pointer
Cache release callback function. It is called by a slab cache to release slabs which are no longer needed by the cache. Slab have a size of cache->slab_size!

Definition at line 77 of file slab.h.


Function Documentation

L4_CV int l4slab_cache_init ( l4slab_cache_t cache,
l4_size_t  size,
unsigned int  max_free,
l4slab_grow_fn_t  grow_fn,
l4slab_release_fn_t  release_fn 
)

Initialize slab cache.

Parameters:
cache Slab cache descriptor
size Size of the cache objects
max_free Maximum number of free slabs allowed in the cache. If more slabs in the slab cache are freed, they are released (if a release callback function is specified).
grow_fn Cache grow callback function, called by the slab cache to allocate new buffers for the cache. If no function is specified the cache cannot allocate buffers on demand.
release_fn Slab release callback function, called by the cache to release unused buffers. If no function is specified unused buffers are not released.
Returns:
0 on success (initialized cache descriptor), error code otherwise:
  • -L4_EINVAL size too big / invalid cache descriptor
Setup cache descriptor. The function initializes the internal cache descriptor structures, but does not allocate any memory. Memory can be added using the l4slab_add_slab() function or memory is allocated on demand by the cache if the grow callback function is specified.

L4_CV void l4slab_destroy ( l4slab_cache_t cache  ) 

Destroy slab cache.

Parameters:
cache Cache descriptor
Release slab descriptor and free all allocated memory. This function is only useful if a release callback function is specified for the cache, otherwise it has no effect.

L4_CV void l4slab_add_slab ( l4slab_cache_t cache,
void *  buffer,
void *  data 
)

Add a slab to the slab cache.

Parameters:
cache Cache descriptor
buffer Pointer to new slab
data Application data
Add the slab (buffer) to the slab cache. Buffer must be cache->slab_size-sized and slab_size aligned in memory.

L4_CV void l4slab_set_data ( l4slab_cache_t cache,
void *  data 
)

Set cache application data pointer.

Parameters:
cache Cache descriptor
data Application data pointer

L4_CV void* l4slab_get_data ( l4slab_cache_t cache  ) 

Get cache application data.

Parameters:
cache Cache descriptor
Returns:
Application data pointer, NULL if invalid cache descriptor or no data pointer set.


Slab Memory Allocator Reference Manual, written by Lars Reuther  © 2000-2003