Go to the source code of this file.
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... | |
| 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.
| os | OS handle. |
| size | Size in bytes of item. |
| count | Number of items in a memory pool. |
| use_lock | TRUE to enable locking of pool. |
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.
| pool | Pointer to memory pool. |
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.
| pool | Pointer to memory pool. |
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.
| pool | Pointer to memory pool. |
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.
| pool | Pointer to memory pool. |
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.
| pool | Pointer to memory pool. |
| idx | Index. |
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.
| pool | Pointer to memory pool. |
| item | Pointer to item to free. |
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.
| pool | Pointer to memory pool. |
| item | Pointer to item to free. |
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.
| pool | Pointer to the pool object. |
Definition at line 131 of file ocs_pool.c.