33Single-linked List
44==================
55
6- Zephyr provides a `` sys_slist_t ` ` type for storing simple
6+ Zephyr provides a :c:struct: ` sys_slist_t ` type for storing simple
77singly-linked list data (i.e. data where each list element stores a
88pointer to the next element, but not the previous one). This supports
99constant-time access to the first (head) and last (tail) elements of
@@ -12,62 +12,62 @@ constant time removal of the head. Removal of subsequent nodes
1212requires access to the "previous" pointer and thus can only be
1313performed in linear time by searching the list.
1414
15- The `` sys_slist_t ` ` struct may be instantiated by the user in any
15+ The :c:struct: ` sys_slist_t ` struct may be instantiated by the user in any
1616accessible memory. It should be initialized with either
17- `` sys_slist_init() ` ` or by static assignment from SYS_SLIST_STATIC_INIT
17+ :c:func: ` sys_slist_init ` or by static assignment from SYS_SLIST_STATIC_INIT
1818before use. Its interior fields are opaque and should not be accessed
1919by user code.
2020
2121The end nodes of a list may be retrieved with
22- `` sys_slist_peek_head() `` and `` sys_slist_peek_tail() ` `, which will
22+ :c:func: ` sys_slist_peek_head ` and :c:func: ` sys_slist_peek_tail `, which will
2323return NULL if the list is empty, otherwise a pointer to a
24- `` sys_snode_t ` ` struct.
24+ :c:struct: ` sys_snode_t ` struct.
2525
26- The `` sys_snode_t ` ` struct represents the data to be inserted. In
26+ The :c:struct: ` sys_snode_t ` struct represents the data to be inserted. In
2727general, it is expected to be allocated/controlled by the user,
2828usually embedded within a struct which is to be added to the list.
2929The container struct pointer may be retrieved from a list node using
30- `` SYS_SLIST_CONTAINER() ` `, passing it the struct name of the
30+ :c:macro: ` SYS_SLIST_CONTAINER `, passing it the struct name of the
3131containing struct and the field name of the node. Internally, the
32- `` sys_snode_t ` ` struct contains only a next pointer, which may be
33- accessed with `` sys_slist_peek_next() ` `.
32+ :c:struct: ` sys_snode_t ` struct contains only a next pointer, which may be
33+ accessed with :c:func: ` sys_slist_peek_next `.
3434
3535Lists may be modified by adding a single node at the head or tail with
36- `` sys_slist_prepend() `` and `` sys_slist_append() ` `. They may also
37- have a node added to an interior point with `` sys_slist_insert() ` `,
36+ :c:func: ` sys_slist_prepend ` and :c:func: ` sys_slist_append `. They may also
37+ have a node added to an interior point with :c:func: ` sys_slist_insert `,
3838which inserts a new node after an existing one. Similarly
39- `` sys_slist_remove() ` ` will remove a node given a pointer to its
39+ :c:func: ` sys_slist_remove ` will remove a node given a pointer to its
4040predecessor. These operations are all constant time.
4141
4242Convenience routines exist for more complicated modifications to a
43- list. `` sys_slist_merge_slist() ` ` will append an entire list to an
44- existing one. `` sys_slist_append_list() ` ` will append a bounded
43+ list. :c:func: ` sys_slist_merge_slist ` will append an entire list to an
44+ existing one. :c:func: ` sys_slist_append_list ` will append a bounded
4545subset of an existing list in constant time. And
46- `` sys_slist_find_and_remove() ` ` will search a list (in linear time)
46+ :c:func: ` sys_slist_find_and_remove ` will search a list (in linear time)
4747for a given node and remove it if present.
4848
4949Finally the slist implementation provides a set of "for each" macros
5050that allows for iterating over a list in a natural way without needing
51- to manually traverse the next pointers. `` SYS_SLIST_FOR_EACH_NODE() ` `
51+ to manually traverse the next pointers. :c:macro: ` SYS_SLIST_FOR_EACH_NODE `
5252will enumerate every node in a list given a local variable to store
53- the node pointer. `` SYS_SLIST_FOR_EACH_NODE_SAFE() ` ` behaves
53+ the node pointer. :c:macro: ` SYS_SLIST_FOR_EACH_NODE_SAFE ` behaves
5454similarly, but has a more complicated implementation that requires an
5555extra scratch variable for storage and allows the user to delete the
5656iterated node during the iteration. Each of those macros also exists
57- in a "container" variant (`` SYS_SLIST_FOR_EACH_CONTAINER() ` ` and
58- `` SYS_SLIST_FOR_EACH_CONTAINER_SAFE() ` `) which assigns a local
57+ in a "container" variant (:c:macro: ` SYS_SLIST_FOR_EACH_CONTAINER ` and
58+ :c:macro: ` SYS_SLIST_FOR_EACH_CONTAINER_SAFE `) which assigns a local
5959variable of a type that matches the user's container struct and not
6060the node struct, performing the required offsets internally. And
61- `` SYS_SLIST_ITERATE_FROM_NODE() ` ` exists to allow for enumerating a
61+ :c:macro: ` SYS_SLIST_ITERATE_FROM_NODE ` exists to allow for enumerating a
6262node and all its successors only, without inspecting the earlier part
6363of the list.
6464
6565Single-linked List Internals
6666----------------------------
6767
6868The slist code is designed to be minimal and conventional.
69- Internally, a `` sys_slist_t ` ` struct is nothing more than a pair of
70- "head" and "tail" pointer fields. And a `` sys_snode_t ` ` stores only a
69+ Internally, a :c:struct: ` sys_slist_t ` struct is nothing more than a pair of
70+ "head" and "tail" pointer fields. And a :c:struct: ` sys_snode_t ` stores only a
7171single "next" pointer.
7272
7373.. figure :: slist.png
@@ -101,14 +101,14 @@ Only one such variant, sflist, exists in Zephyr at the moment.
101101Flagged List
102102------------
103103
104- The `` sys_sflist_t ` ` is implemented using the described genlist
104+ The :c:struct: ` sys_sflist_t ` is implemented using the described genlist
105105template API. With the exception of symbol naming ("sflist" instead
106106of "slist") and the additional API described next, it operates in all
107107ways identically to the slist API.
108108
109109It adds the ability to associate exactly two bits of user defined
110110"flags" with each list node. These can be accessed and modified with
111- `` sys_sflist_flags_get() `` and `` sys_sflist_flags_get() ` `.
111+ :c:func: ` sys_sfnode_flags_get ` and :c:func: ` sys_sfnode_flags_get `.
112112Internally, the flags are stored unioned with the bottom bits of the
113113next pointer and incur no SRAM storage overhead when compared with the
114114simpler slist code.
0 commit comments