FreeList.h File Reference
`#include "ithread.h"`
`#include <errno.h>`
Include dependency graph for FreeList.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | FREELISTNODE
struct | FREELIST

## Typedefs

typedef struct FREELISTNODE | FreeListNode
typedef struct FREELIST | FreeList

## Functions

int | FreeListInit (FreeList *free_list, size_t elementSize, int maxFreeListLength)
| Initializes Free List. More...
void * | FreeListAlloc (FreeList *free_list)
| Allocates chunk of set size. More...
int | FreeListFree (FreeList *free_list, void *element)
| Returns an item to the Free List. More...
int | FreeListDestroy (FreeList *free_list)
| Releases the resources stored with the free list. More...

## Typedef Documentation

## FreeList

typedef struct FREELIST FreeList

Stores head and size of free list, as well as mutex for protection.

## FreeListNode

typedef struct FREELISTNODE FreeListNode

Free list node. points to next free item. Memory for node is borrowed from allocated items.

## Function Documentation

## 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.

Referenced by CreateThreadPoolJob(), and CreateTimerEvent().

## 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.

Referenced by ListDestroy().

## 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.

Referenced by FreeThreadPoolJob(), and FreeTimerEvent().

## 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.

Referenced by ListInit().