Manage a free list (for internal use only). More...
#include <UPnPsdk/pthread.hpp>
Go to the source code of this file.
Classes | |
struct | FreeListNode |
Free list node. points to next free item. More... | |
struct | FreeList |
Stores head and size of free list, as well as mutex for protection. More... | |
Functions | |
int | FreeListInit (FreeList *free_list, size_t elementSize, int maxFreeListLength) |
Initializes Free List. | |
void * | FreeListAlloc (FreeList *free_list) |
Allocates chunk of set size. | |
int | FreeListFree (FreeList *free_list, void *element) |
Returns an item to the Free List. | |
int | FreeListDestroy (FreeList *free_list) |
Releases the resources stored with the free list. | |
Manage a free list (for internal use only).
Because this is for internal use, parameters are NOT checked for validity. The caller must ensure valid parameters.
Definition in file FreeList.hpp.
struct FreeListNode |
Free list node. points to next free item.
Memory for node is borrowed from allocated items.
Definition at line 55 of file FreeList.hpp.
Class Members | ||
---|---|---|
struct FreeListNode * | next |
struct FreeList |
Stores head and size of free list, as well as mutex for protection.
Definition at line 63 of file FreeList.hpp.
Class Members | ||
---|---|---|
FreeListNode * | head | |
size_t | element_size | |
int | maxFreeListLength | |
int | freeListLength |
int FreeListInit | ( | FreeList * | free_list, |
size_t | elementSize, | ||
int | maxFreeListLength | ||
) |
Initializes Free List.
Must be called first and only once for FreeList.
[in] | free_list | Must be valid, non null, pointer to a linked list. |
[in] | elementSize | Size of elements to store in free list. |
[in] | maxFreeListLength | Max size that the free list can grow to before returning memory to the operating system |
Definition at line 50 of file FreeList.cpp.
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 operating system to allocate memory.
[in] | free_list | Must be valid, non null, pointer to a linked list. |
Definition at line 64 of file FreeList.cpp.
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 operating system.
[in] | free_list | Must be valid, non null, pointer to a free list. |
[in] | element | Must be a pointer allocated by FreeListAlloc. |
Definition at line 83 of file FreeList.cpp.
int FreeListDestroy | ( | FreeList * | free_list | ) |
Releases the resources stored with the free list.
[in] | free_list | Must be valid, non null, pointer to a linked list. |
Definition at line 103 of file FreeList.cpp.