@file aws_doubly_linked_list.h Doubly Linked List implementation. A generic implementation of circular Doubly Linked List which consists of a list head and some list entries (zero in case of an empty list). To start with, a structure of type Link_t should be embedded in the structure which is to be organized as doubly linked list.
typedef struct UserStruct
{
uint32_t ulField1;
uint32_t ulField2;
Link_t xLink;
} UserStruct_t;
A List head should then be defined and initialized.
Link_t xListHead;
listINIT_HEAD( &xListHead );
listADD can then be used to add nodes to the list.
listADD( &( xListHead ), &( pxUserStruct->xLink ) );
listFOR_EACH can be used for traversing the list.
Link_t *pxLink;
UserStruct_t *pxUserStruct;
listFOR_EACH( pxLink, &( xListHead ) )
{
pxUserStruct = listCONTAINER( pxLink, UserStruct_t, xLink );
}
listFOR_EACH_SAFE should be used if you want to perform destructive operations (like free) on nodes while traversing the list.
Link_t *pxLink, *pxTempLink;
UserStruct_t *pxUserStruct;
listFOR_EACH( pxLink, pxTempLink, &( xListHead ) )
{
pxUserStruct = listCONTAINER( pxLink, UserStruct_t, xLink );
free( pxUserStruct );
}