#include "ithread.h"
#include <errno.h>
Go to the source code of this file.
◆ FreeList
Stores head and size of free list, as well as mutex for protection.
◆ FreeListNode
Free list node. points to next free item. Memory for node is borrowed from allocated items.
◆ FreeListAlloc()
void * FreeListAlloc |
( |
FreeList * |
free_list | ) |
|
Allocates chunk of set size.
If a free item is available in the list, returnes the stored item, otherwise calls the O.S. to allocate memory.
- Returns
- Non NULL on success. NULL on failure.
- Parameters
-
free_list | Must be valid, non null, pointer to a linked list. |
◆ FreeListDestroy()
int FreeListDestroy |
( |
FreeList * |
free_list | ) |
|
Releases the resources stored with the free list.
- Returns
- :
0
on success.
EINVAL
on failure.
- Parameters
-
free_list | Must be valid, non null, pointer to a linked list. |
◆ FreeListFree()
int FreeListFree |
( |
FreeList * |
free_list, |
|
|
void * |
element |
|
) |
| |
Returns an item to the Free List.
If the free list is smaller than the max size then adds the item to the free list, otherwise returns the item to the O.S.
- Returns
- :
0
on success.
EINVAL
on failure.
- Parameters
-
free_list | Must be valid, non null, pointer to a free list. |
element | Must be a pointer allocated by FreeListAlloc. |
◆ FreeListInit()
int FreeListInit |
( |
FreeList * |
free_list, |
|
|
size_t |
elementSize, |
|
|
int |
maxFreeListLength |
|
) |
| |
Initializes Free List.
Must be called first and only once for FreeList.
- Returns
- :
0
on success.
EINVAL
on failure.
- Parameters
-
free_list | Must be valid, non null, pointer to a linked list. |
elementSize | Size of elements to store in free list. |
maxFreeListLength | Max size that the free list can grow to before returning memory to O.S. |