Data Structures | Typedefs | Functions
List.h File Reference

Detailed Description

Linked List interface for use in drivers.

============================================================================

This module provides simple doubly-link list implementation. There are two main structures:

The following shows how to create a linked list with three elements.

+ denotes null-terminated
_______ _______ _______ _______
|_______|----->|_______|----->|_______|--->|_______|--//---,
,----|_______| ,-|_______|<-----|_______|<---|_______|<-//-, +
| List + elem elem elem |
|_____________________________________________________________|

The APIs List_get, List_put, and List_putHead are atomic. The other APIs are not necessarily atomic. In other words, when traversing a linked list, it is up to the application to provide thread-safety (e.g. HwiP_disable/restore or MutexP_pend/post).

Initializing and adding an element to the tail and removing it

typedef struct {
List_Elem elem;
void *buffer;
} MyStruct;
List_List list;
MyStruct foo;
MyStruct *bar;
List_put(&list, (List_Elem *)&foo);
bar = (MyStruct *)List_get(&list);

The List_put and List_get APIs are used to maintain a first-in first-out (FIFO) linked list.

The List_putHead and List_get APIs are used to maintain a last-in first-out (LIFO) linked list.

Traversing a list from head to tail. Note: thread-safety calls are not shown here.

List_List list;
List_Elem *temp;
for (temp = List_head(&list); temp != NULL; temp = List_next(temp)) {
printf("address = 0x%x\n", temp);
}

Traversing a list from tail to head. Note: thread-safety calls are not shown here.

List_List list;
List_Elem *temp;
for (temp = List_tail(&list); temp != NULL; temp = List_prev(temp)) {
printf("address = 0x%x\n", temp);
}

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
Include dependency graph for List.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  List_Elem_
 
struct  List_List
 

Typedefs

typedef struct List_Elem_ List_Elem
 

Functions

void List_clearList (List_List *list)
 Function to initialize the contents of a List_List. More...
 
static bool List_empty (List_List *list)
 Function to test whether a linked list is empty. More...
 
List_ElemList_get (List_List *list)
 Function to atomically get the first elem in a linked list. More...
 
static List_ElemList_head (List_List *list)
 Function to return the head of a linked list. More...
 
void List_insert (List_List *list, List_Elem *newElem, List_Elem *curElem)
 Function to insert an elem into a linked list. More...
 
static List_ElemList_next (List_Elem *elem)
 Function to return the next elem in a linked list. More...
 
static List_ElemList_prev (List_Elem *elem)
 Function to return the prev elem in a linked list. More...
 
void List_put (List_List *list, List_Elem *elem)
 Function to atomically put an elem onto the end of a linked list. More...
 
void List_putHead (List_List *list, List_Elem *elem)
 Function to atomically put an elem onto the head of a linked list. More...
 
void List_remove (List_List *list, List_Elem *elem)
 Function to remove an elem from a linked list. More...
 
static List_ElemList_tail (List_List *list)
 Function to return the tail of a linked list. More...
 

Typedef Documentation

§ List_Elem

typedef struct List_Elem_ List_Elem

Function Documentation

§ List_clearList()

void List_clearList ( List_List list)

Function to initialize the contents of a List_List.

Parameters
listPointer to a List_List structure that will be used to maintain a linked list

§ List_empty()

static bool List_empty ( List_List list)
inlinestatic

Function to test whether a linked list is empty.

Parameters
listA pointer to a linked list
Returns
true if empty, false if not empty

References List_List::head, and List_get().

§ List_get()

List_Elem* List_get ( List_List list)

Function to atomically get the first elem in a linked list.

Parameters
listA pointer to a linked list
Returns
Pointer the first elem in the linked list or NULL if empty

Referenced by List_empty().

§ List_head()

static List_Elem* List_head ( List_List list)
inlinestatic

Function to return the head of a linked list.

This function does not remove the head, it simply returns a pointer to it. This function is typically used when traversing a linked list.

Parameters
listA pointer to the linked list
Returns
Pointer to the first elem in the linked list or NULL if empty

References List_List::head, and List_insert().

§ List_insert()

void List_insert ( List_List list,
List_Elem newElem,
List_Elem curElem 
)

Function to insert an elem into a linked list.

Parameters
listA pointer to the linked list
newElemNew elem to insert
curElemElem to insert the newElem in front of. This value cannot be NULL.

Referenced by List_head().

§ List_next()

static List_Elem* List_next ( List_Elem elem)
inlinestatic

Function to return the next elem in a linked list.

This function does not remove the elem, it simply returns a pointer to next one. This function is typically used when traversing a linked list.

Parameters
elemElem in the list
Returns
Pointer to the next elem in linked list or NULL if at the end

References List_Elem_::next.

§ List_prev()

static List_Elem* List_prev ( List_Elem elem)
inlinestatic

Function to return the prev elem in a linked list.

This function does not remove the elem, it simply returns a pointer to prev one. This function is typically used when traversing a linked list.

Parameters
elemElem in the list
Returns
Pointer to the prev elem in linked list or NULL if at the beginning

References List_put(), List_putHead(), List_remove(), and List_Elem_::prev.

§ List_put()

void List_put ( List_List list,
List_Elem elem 
)

Function to atomically put an elem onto the end of a linked list.

Parameters
listA pointer to the linked list
elemElement to place onto the end of the linked list

Referenced by List_prev().

§ List_putHead()

void List_putHead ( List_List list,
List_Elem elem 
)

Function to atomically put an elem onto the head of a linked list.

Parameters
listA pointer to the linked list
elemElement to place onto the beginning of the linked list

Referenced by List_prev().

§ List_remove()

void List_remove ( List_List list,
List_Elem elem 
)

Function to remove an elem from a linked list.

Parameters
listA pointer to the linked list
elemElement to be removed from a linked list

Referenced by List_prev().

§ List_tail()

static List_Elem* List_tail ( List_List list)
inlinestatic

Function to return the tail of a linked list.

This function does not remove the tail, it simply returns a pointer to it. This function is typically used when traversing a linked list.

Parameters
listA pointer to the linked list
Returns
Pointer to the last elem in the linked list or NULL if empty

References List_List::tail.

© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale