Rtos API example
ns_list.h File Reference
Linked list support library. More...
Go to the source code of this file.
Data Structures | |
struct | ns_list |
Underlying generic linked list head. More... | |
struct | ns_list_link |
The type for the link member in the user's entry structure. More... | |
Typedefs | |
typedef struct ns_list | ns_list_t |
Underlying generic linked list head. | |
typedef uint_fast8_t | ns_list_offset_t |
Type used to pass link offset to underlying functions. | |
typedef struct ns_list_link | ns_list_link_t |
The type for the link member in the user's entry structure. |
Detailed Description
Linked list support library.
The ns_list.h file provides a doubly-linked list/queue, providing O(1) performance for all insertion/removal operations, and access to either end of the list.
Memory footprint is two pointers for the list head, and two pointers in each list entry. It is similar in concept to BSD's TAILQ.
Although the API is symmetrical and O(1) in both directions, due to internal pointer design, it is *slightly* more efficient to insert at the end when used as a queue, and to iterate forwards rather than backwards.
Example of an entry type that can be stored to this list. ~~~ typedef struct example_entry { uint8_t *data; uint32_t data_count; ns_list_link_t link; } example_entry_t;
static NS_LIST_HEAD(example_entry_t, link) my_list; ns_list_init(&my_list); ~~~ OR ~~~ NS_LIST_HEAD(example_entry_t, link) my_list = NS_LIST_INIT(my_list); ~~~ OR ~~~ static NS_LIST_DEFINE(my_list, example_entry_t, link); ~~~ OR ~~~ typedef NS_LIST_HEAD(example_entry_t, link) example_list_t; example_list_t NS_LIST_NAME_INIT(my_list); ~~~ NOTE: the link field SHALL NOT be accessed by the user.
An entry can exist on multiple lists by having multiple link fields.
All the list operations are implemented as macros, most of which are backed by optionally-inline functions. The macros do not evaluate any arguments more than once, unless documented.
In macro documentation, `list_t` refers to a list type defined using NS_LIST_HEAD(), and `entry_t` to the entry type that was passed to it.
Definition in file ns_list.h.
Typedef Documentation
typedef struct ns_list_link ns_list_link_t |
The type for the link member in the user's entry structure.
Users should not access this member directly - just pass its name to the list head macros. The funny prev pointer simplifies common operations (eg insertion, removal), at the expense of complicating rare reverse iteration.
NB - the list implementation relies on next being the first member.
typedef uint_fast8_t ns_list_offset_t |
Generated on Sun Jul 17 2022 08:25:35 by 1.7.2