Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_pool.c File Reference
#include "ocs_os.h"
#include "ocs_pool.h"

Go to the source code of this file.

Detailed Description

The ocs_pool_t data structure consists of:

pool->a An ocs_array_t. pool->freelist A linked list of free items.

When a pool is allocated using ocs_pool_alloc(), the caller provides the size in bytes of each memory pool item (size), and a count of items (count). Since ocs_pool_alloc() has no visibility into the object the caller is allocating, a link for the linked list is "pre-pended". Thus when allocating the ocs_array_t, the size used is the size of the pool_hdr_t plus the requested memory pool item size.

array item layout:

pool_hdr_t pool data[size]

The address of the pool data is returned when allocated (using ocs_pool_get(), or ocs_pool_get_instance()), and received when being freed (using ocs_pool_put(). So the address returned by the array item (ocs_array_get()) must be offset by the size of pool_hdr_t.

Definition in file ocs_pool.c.

Data Structures

struct  ocs_pool_t
 
struct  pool_hdr_t
 

Functions

ocs_pool_t * ocs_pool_alloc (ocs_os_handle_t os, uint32_t size, uint32_t count, uint32_t use_lock)
 Allocate a memory pool. More...
 
void ocs_pool_reset (ocs_pool_t *pool)
 Reset a memory pool. More...
 
void ocs_pool_free (ocs_pool_t *pool)
 Free a previously allocated memory pool. More...
 
void * ocs_pool_get (ocs_pool_t *pool)
 Allocate a memory pool item. More...
 
void ocs_pool_put (ocs_pool_t *pool, void *item)
 free memory pool item More...
 
void ocs_pool_put_head (ocs_pool_t *pool, void *item)
 free memory pool item More...
 
uint32_t ocs_pool_get_count (ocs_pool_t *pool)
 Return memory pool item count. More...
 
void * ocs_pool_get_instance (ocs_pool_t *pool, uint32_t idx)
 Return item given an index. More...
 
uint32_t ocs_pool_get_freelist_count (ocs_pool_t *pool)
 Return count of free objects in a pool. More...
 

Function Details

ocs_pool_t* ocs_pool_alloc ( ocs_os_handle_t  os,
uint32_t  size,
uint32_t  count,
uint32_t  use_lock 
)

Allocate a memory pool.

A memory pool of given size and item count is allocated.

Parameters
osOS handle.
sizeSize in bytes of item.
countNumber of items in a memory pool.
use_lockTRUE to enable locking of pool.
Returns
Returns pointer to allocated memory pool, or NULL.

Definition at line 88 of file ocs_pool.c.

void ocs_pool_free ( ocs_pool_t *  pool)

Free a previously allocated memory pool.

The memory pool is freed.

Parameters
poolPointer to memory pool.
Returns
None.

Definition at line 173 of file ocs_pool.c.

void* ocs_pool_get ( ocs_pool_t *  pool)

Allocate a memory pool item.

A memory pool item is taken from the free list and returned.

Parameters
poolPointer to memory pool.
Returns
Pointer to allocated item, otherwise NULL if there are no unallocated items.

Definition at line 197 of file ocs_pool.c.

uint32_t ocs_pool_get_count ( ocs_pool_t *  pool)

Return memory pool item count.

Returns the allocated number of items.

Parameters
poolPointer to memory pool.
Returns
Returns count of allocated items.

Definition at line 291 of file ocs_pool.c.

uint32_t ocs_pool_get_freelist_count ( ocs_pool_t *  pool)

Return count of free objects in a pool.

The number of objects on a pool's free list.

Parameters
poolPointer to memory pool.
Returns
Returns count of objects on free list.

Definition at line 335 of file ocs_pool.c.

void* ocs_pool_get_instance ( ocs_pool_t *  pool,
uint32_t  idx 
)

Return item given an index.

A pointer to a memory pool item is returned given an index.

Parameters
poolPointer to memory pool.
idxIndex.
Returns
Returns pointer to item, or NULL if index is invalid.

Definition at line 315 of file ocs_pool.c.

void ocs_pool_put ( ocs_pool_t *  pool,
void *  item 
)

free memory pool item

A memory pool item is freed.

Parameters
poolPointer to memory pool.
itemPointer to item to free.
Returns
None.

Definition at line 230 of file ocs_pool.c.

void ocs_pool_put_head ( ocs_pool_t *  pool,
void *  item 
)

free memory pool item

A memory pool item is freed to head of list.

Parameters
poolPointer to memory pool.
itemPointer to item to free.
Returns
None.

Definition at line 261 of file ocs_pool.c.

void ocs_pool_reset ( ocs_pool_t *  pool)

Reset a memory pool.

Place all pool elements on the free list, and zero them.

Parameters
poolPointer to the pool object.
Returns
None.

Definition at line 131 of file ocs_pool.c.