My Project
Generic Linked List

Classes

struct  MMAL_LIST_ELEMENT_T
 
struct  MMAL_LIST_T
 

Typedefs

typedef struct MMAL_LIST_ELEMENT_T MMAL_LIST_ELEMENT_T
 
typedef struct MMAL_LIST_T MMAL_LIST_T
 
typedef int(* MMAL_LIST_COMPARE_T) (MMAL_LIST_ELEMENT_T *lhs, MMAL_LIST_ELEMENT_T *rhs)
 

Functions

MMAL_LIST_Tmmal_list_create (void)
 
void mmal_list_destroy (MMAL_LIST_T *list)
 
MMAL_LIST_ELEMENT_Tmmal_list_pop_back (MMAL_LIST_T *list)
 
MMAL_LIST_ELEMENT_Tmmal_list_pop_front (MMAL_LIST_T *list)
 
void mmal_list_push_front (MMAL_LIST_T *list, MMAL_LIST_ELEMENT_T *element)
 
void mmal_list_push_back (MMAL_LIST_T *list, MMAL_LIST_ELEMENT_T *element)
 
void mmal_list_insert (MMAL_LIST_T *list, MMAL_LIST_ELEMENT_T *element, MMAL_LIST_COMPARE_T compare)
 

Detailed Description

This provides a thread-safe implementation of a linked list which can be used with any data type.

Typedef Documentation

◆ MMAL_LIST_COMPARE_T

typedef int(* MMAL_LIST_COMPARE_T) (MMAL_LIST_ELEMENT_T *lhs, MMAL_LIST_ELEMENT_T *rhs)

List comparison function. This is supplied by a client when inserting an element in the middle of the list. The list will always insert a smaller element in front of a larger element.

Returns
TRUE: lhs < rhs FALSE: lhs >= rhs

Definition at line 108 of file mmal_list.h.

◆ MMAL_LIST_ELEMENT_T

Single element in the list

◆ MMAL_LIST_T

typedef struct MMAL_LIST_T MMAL_LIST_T

Linked list type. Clients shouldn't modify this directly. Use the provided API functions to add new elements. The public members are only for debug purposes.

Function Documentation

◆ mmal_list_create()

MMAL_LIST_T* mmal_list_create ( void  )

Create a new linked list.

Returns
Pointer to new queue (NULL on failure).

◆ mmal_list_destroy()

void mmal_list_destroy ( MMAL_LIST_T list)

Destroy a linked list.

Parameters
listList to destroy

◆ mmal_list_insert()

void mmal_list_insert ( MMAL_LIST_T list,
MMAL_LIST_ELEMENT_T element,
MMAL_LIST_COMPARE_T  compare 
)

Insert an element into the list. The location where the element is inserted is determined using the supplied comparison function. Smaller elements are inserted in front of larger elements.

Parameters
listList to add to
elementThe element to insert
compareComparison function supplied by the client

◆ mmal_list_pop_back()

MMAL_LIST_ELEMENT_T* mmal_list_pop_back ( MMAL_LIST_T list)

Remove the last element in the list.

Parameters
listList to remove from
Returns
Pointer to the last element (or NULL if empty)

◆ mmal_list_pop_front()

MMAL_LIST_ELEMENT_T* mmal_list_pop_front ( MMAL_LIST_T list)

Remove the first element in the list.

Parameters
listList to remove from
Returns
Pointer to the first element (or NULL if empty)

◆ mmal_list_push_back()

void mmal_list_push_back ( MMAL_LIST_T list,
MMAL_LIST_ELEMENT_T element 
)

Add an element to the back of the list.

Parameters
listList to add to
elementThe element to add

◆ mmal_list_push_front()

void mmal_list_push_front ( MMAL_LIST_T list,
MMAL_LIST_ELEMENT_T element 
)

Add an element to the front of the list.

Parameters
listList to add to
elementThe element to add