Skip to content

Commit d31d6ce

Browse files
committed
doc: strcutures: use doxygen to reference functions
Use :c:func:`..` possible to reference and link doxygen documentation. Signed-off-by: Anas Nashif <[email protected]>
1 parent e9662c8 commit d31d6ce

File tree

5 files changed

+74
-73
lines changed

5 files changed

+74
-73
lines changed

doc/reference/data_structures/dlist.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,47 @@ the head, tail or any internal node). To do this, the list stores two
1111
pointers per node, and thus has somewhat higher runtime code and
1212
memory space needs.
1313

14-
A ``sys_dlist_t`` struct may be instantiated by the user in any
15-
accessible memory. It must be initialized with ``sys_dlist_init()``
16-
or ``SYS_DLIST_STATIC_INIT()`` before use. The ``sys_dnode_t`` struct
14+
A :c:struct:`sys_dlist_t` struct may be instantiated by the user in any
15+
accessible memory. It must be initialized with :c:func:`sys_dlist_init`
16+
or :c:macro:`SYS_DLIST_STATIC_INIT` before use. The :c:struct:`sys_dnode_t` struct
1717
is expected to be provided by the user for any nodes addded to the
1818
list (typically embedded within the struct to be tracked, as described
1919
above). It must be initialized in zeroed/bss memory or with
20-
``sys_dnode_init()`` before use.
20+
:c:func:`sys_dnode_init` before use.
2121

2222
Primitive operations may retrieve the head/tail of a list and the
23-
next/prev pointers of a node with ``sys_dlist_peek_head()``,
24-
``sys_dlist_peek_tail()``, ``sys_dlist_peek_next()`` and
25-
``sys_dlist_peek_prev()``. These can all return NULL where
23+
next/prev pointers of a node with :c:func:`sys_dlist_peek_head`,
24+
:c:func:`sys_dlist_peek_tail`, :c:func:`sys_dlist_peek_next` and
25+
:c:func:`sys_dlist_peek_prev`. These can all return NULL where
2626
appropriate (i.e. for empty lists, or nodes at the endpoints of the
2727
list).
2828

2929
A dlist can be modified in constant time by removing a node with
30-
``sys_dlist_remove()``, by adding a node to the head or tail of a list
31-
with ``sys_dlist_prepend()`` and ``sys_dlist_append()``, or by
32-
inserting a node before an existing node with ``sys_dlist_insert()``.
30+
:c:func:`sys_dlist_remove`, by adding a node to the head or tail of a list
31+
with :c:func:`sys_dlist_prepend` and :c:func:`sys_dlist_append`, or by
32+
inserting a node before an existing node with :c:func:`sys_dlist_insert`.
3333

3434
As for slist, each node in a dlist can be processed in a natural code
35-
block style using ``SYS_DLIST_FOR_EACH_NODE()``. This macro also
35+
block style using :c:macro:`SYS_DLIST_FOR_EACH_NODE`. This macro also
3636
exists in a "FROM_NODE" form which allows for iterating from a known
3737
starting point, a "SAFE" variant that allows for removing the node
3838
being inspected within the code block, a "CONTAINER" style that
3939
provides the pointer to a containing struct instead of the raw node,
4040
and a "CONTAINER_SAFE" variant that provides both properties.
4141

4242
Convenience utilities provided by dlist include
43-
``sys_dlist_insert_at()``, which inserts a node that linearly searches
43+
:c:func:`sys_dlist_insert_at`, which inserts a node that linearly searches
4444
through a list to find the right insertion point, which is provided by
4545
the user as a C callback function pointer, and
46-
``sys_dlist_is_linked()``, which will affirmatively return whether or
46+
:c:func:`sys_dnode_is_linked`, which will affirmatively return whether or
4747
not a node is currently linked into a dlist or not (via an
4848
implementation that has zero overhead vs. the normal list processing).
4949

5050
Double-linked List Internals
5151
----------------------------
5252

53-
Internally, the dlist implementation is minimal: the ``sys_dlist_t``
54-
struct contains "head" and "tail" pointer fields, the ``sys_dnode_t``
53+
Internally, the dlist implementation is minimal: the :c:struct:`sys_dlist_t`
54+
struct contains "head" and "tail" pointer fields, the :c:struct:`sys_dnode_t`
5555
contains "prev" and "next" pointers, and no other data is stored. But
5656
in practice the two structs are internally identical, and the list
5757
struct is inserted as a node into the list itself. This allows for a

doc/reference/data_structures/rbtree.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,56 @@ which has runtimes on search and removal operations bounded at
1010
O(log2(N)) for a tree of size N. This is implemented using a
1111
conventional red/black tree as described by multiple academic sources.
1212

13-
The ``struct rbtree`` tracking struct for a rbtree may be initialized
13+
The :c:struct:`rbtree` tracking struct for a rbtree may be initialized
1414
anywhere in user accessible memory. It should contain only zero bits
1515
before first use. No specific initialization API is needed or
1616
required.
1717

1818
Unlike a list, where position is explicit, the ordering of nodes
1919
within an rbtree must be provided as a predicate function by the user.
20-
A function of type ``rb_lessthan_t()`` should be assigned to the
21-
``lessthan_fn`` field of the ``struct rbtree`` before any tree
20+
A function of type :c:func:`rb_lessthan_t` should be assigned to the
21+
``lessthan_fn`` field of the :c:struct`rbtree` struct before any tree
2222
operations are attempted. This function should, as its name suggests,
2323
return a boolean True value if the first node argument is "less than"
2424
the second in the ordering desired by the tree. Note that "equal" is
2525
not allowed, nodes within a tree must have a single fixed order for
2626
the algorithm to work correctly.
2727

2828
As with the slist and dlist containers, nodes within an rbtree are
29-
represented as a ``struct rbnode`` structure which exists in
29+
represented as a :c:struct:`rbnode` structure which exists in
3030
user-managed memory, typically embedded within the the data structure
3131
being tracked in the tree. Unlike the list code, the data within an
3232
rbnode is entirely opaque. It is not possible for the user to extract
3333
the binary tree topology and "manually" traverse the tree as it is for
3434
a list.
3535

36-
Nodes can be inserted into a tree with ``rb_insert()`` and removed
37-
with ``rb_remove()``. Access to the "first" and "last" nodes within a
36+
Nodes can be inserted into a tree with :c:func:`rb_insert` and removed
37+
with :c:func:`rb_remove`. Access to the "first" and "last" nodes within a
3838
tree (in the sense of the order defined by the comparison function) is
39-
provided by ``rb_get_min()`` and ``rb_get_max()``. There is also a
40-
predicate, ``rb_contains()``, which returns a boolean True if the
39+
provided by :c:func:`rb_get_min` and :c:func:`rb_get_max`. There is also a
40+
predicate, :c:func:`rb_contains`, which returns a boolean True if the
4141
provided node pointer exists as an element within the tree. As
4242
described above, all of these routines are guaranteed to have at most
4343
log time complexity in the size of the tree.
4444

4545
There are two mechanisms provided for enumerating all elements in an
46-
rbtree. The first, ``rb_walk()``, is a simple callback implementation
46+
rbtree. The first, :c:func:`rb_walk`, is a simple callback implementation
4747
where the caller specifies a C function pointer and an untyped
4848
argument to be passed to it, and the tree code calls that function for
4949
each node in order. This has the advantage of a very simple
5050
implementation, at the cost of a somewhat more cumbersome API for the
51-
user (not unlike ISO C's ``bsearch()`` routine). It is a recursive
51+
user (not unlike ISO C's :c:func:`bsearch` routine). It is a recursive
5252
implementation, however, and is thus not always available in
5353
environments that forbid the use of unbounded stack techniques like
5454
recursion.
5555

56-
There is also a ``RB_FOR_EACH()`` iterator provided, which, like the
56+
There is also a :c:macro:`RB_FOR_EACH` iterator provided, which, like the
5757
similar APIs for the lists, works to iterate over a list in a more
5858
natural way, using a nested code block instead of a callback. It is
5959
also nonrecursive, though it requires log-sized space on the stack by
6060
default (however, this can be configured to use a fixed/maximally size
6161
buffer instead where needed to avoid the dynamic allocation). As with
62-
the lists, this is also available in a ``RB_FOR_EACH_CONTAINER()``
62+
the lists, this is also available in a :c:macro:`RB_FOR_EACH_CONTAINER`
6363
variant which enumerates using a pointer to a container field and not
6464
the raw node pointer.
6565

@@ -94,12 +94,12 @@ modification.
9494
These rotations are conceptually implemented on top of a primitive
9595
that "swaps" the position of one node with another in the list.
9696
Typical implementations effect this by simply swapping the nodes
97-
internal "data" pointers, but because the Zephyr ``struct rbnode`` is
97+
internal "data" pointers, but because the Zephyr :c:struct:`rbnode` is
9898
intrusive, that cannot work. Zephyr must include somewhat more
9999
elaborate code to handle the edge cases (for example, one swapped node
100100
can be the root, or the two may already be parent/child).
101101

102-
The ``struct rbnode`` struct for a Zephyr rbtree contains only two
102+
The :c:struct:`rbnode` struct for a Zephyr rbtree contains only two
103103
pointers, representing the "left", and "right" children of a node
104104
within the binary tree. Traversal of a tree for rebalancing following
105105
modification, however, routinely requires the ability to iterate

doc/reference/data_structures/ring_buffers.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,62 +52,62 @@ data buffer to empty.
5252

5353

5454
A ``struct ring_buf`` may be placed anywhere in user-accessible
55-
memory, and must be initialized with ``ring_buf_init()`` before use.
55+
memory, and must be initialized with :c:func:`ring_buf_init` before use.
5656
This must be provided a region of user-controlled memory for use as
5757
the buffer itself. Note carefully that the units of the size of the
5858
buffer passed change (either bytes or words) depending on how the ring
5959
buffer will be used later. Macros for combining these steps in a
6060
single static declaration exist for convenience.
61-
``RING_BUF_DECLARE()`` will declare and statically initialize a ring
61+
:c:macro:`RING_BUF_DECLARE` will declare and statically initialize a ring
6262
buffer with a specified byte count, where
63-
``RING_BUF_ITEM_DECLARE_SIZE()`` will declare and statically
63+
:c:macro:`RING_BUF_ITEM_DECLARE_SIZE` will declare and statically
6464
initialize a buffer with a given count of 32 bit words.
65-
``RING_BUF_ITEM_DECLARE_POW2()`` can be used to initialize an
65+
:c:macro:`RING_BUF_ITEM_DECLARE_POW2` can be used to initialize an
6666
items-mode buffer with a memory region guaranteed to be a power of
6767
two, which enables various optimizations internal to the
6868
implementation. No power-of-two initialization is available for
6969
bytes-mode ring buffers.
7070

7171
"Bytes" data may be copied into the ring buffer using
72-
``ring_buf_put()``, passing a data pointer and byte count. These
72+
:c:func:`ring_buf_put`, passing a data pointer and byte count. These
7373
bytes will be copied into the buffer in order, as many as will fit in
7474
the allocated buffer. The total number of bytes copied (which may be
75-
fewer than provided) will be returned. Likewise ``ring_buf_get()``
75+
fewer than provided) will be returned. Likewise :c:func:`ring_buf_get`
7676
will copy bytes out of the ring buffer in the order that they were
7777
written, into a user-provided buffer, returning the number of bytes
7878
that were transferred.
7979

8080
To avoid multiply-copied-data situations, a "claim" API exists for
81-
byte mode. ``ring_buf_put_claim()`` takes a byte size value from the
81+
byte mode. :c:func:`ring_buf_put_claim` takes a byte size value from the
8282
user and returns a pointer to memory internal to the ring buffer that
8383
can be used to receive those bytes, along with a size of the
8484
contiguous internal region (which may be smaller than requested). The
8585
user can then copy data into that region at a later time without
8686
assembling all the bytes in a single region first. When complete,
87-
``ring_buf_put_finish()`` can be used to signal the buffer that the
87+
:c:func:`ring_buf_put_finish` can be used to signal the buffer that the
8888
transfer is complete, passing the number of bytes actually
8989
transferred. At this point a new transfer can be initiated.
90-
Similarly, ``ring_buf_get_claim()`` returns a pointer to internal ring
90+
Similarly, :c:func:`ring_buf_get_claim` returns a pointer to internal ring
9191
buffer data from which the user can read without making a verbatim
92-
copy, and ``ring_buf_get_finish()`` signals the buffer with how many
92+
copy, and :c:func:`ring_buf_get_finish` signals the buffer with how many
9393
bytes have been consumed and allows for a new transfer to begin.
9494

9595
"Items" mode works similarly to bytes mode, except that all transfers
9696
are in units of 32 bit words and all memory is assumed to be aligned
9797
on 32 bit boundaries. The write and read operations are
98-
``ring_buf_item_put()`` and ``ring_buf_item_get()``, and work
98+
:c:func:`ring_buf_item_put` and :c:func:`ring_buf_item_get`, and work
9999
otherwise identically to the bytes mode APIs. There no "claim" API
100100
provided for items mode. One important difference is that unlike
101-
``ring_buf_put()``, ``ring_buf_item_put()`` will not do a partial
101+
:c:func:`ring_buf_put`, :c:func:`ring_buf_item_put` will not do a partial
102102
transfer; it will return an error in the case where the provided data
103103
does not fit in its entirety.
104104

105105
The user can manage the capacity of a ring buffer without modifying it
106-
using the ``ring_buf_space_get()`` call (which returns a value of
106+
using the :c:func:`ring_buf_space_get` call (which returns a value of
107107
either bytes or items depending on how the ring buffer has been used),
108-
or by testing the ``ring_buf_is_empty()`` predicate.
108+
or by testing the :c:func:`ring_buf_is_empty` predicate.
109109

110-
Finally, a ``ring_buf_reset()`` call exists to immediately empty a
110+
Finally, a :c:func:`ring_buf_reset` call exists to immediately empty a
111111
ring buffer, discarding the tracking of any bytes or items already
112112
written to the buffer. It does not modify the memory contents of the
113113
buffer itself, however.

doc/reference/data_structures/slist.rst

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Single-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
77
singly-linked list data (i.e. data where each list element stores a
88
pointer to the next element, but not the previous one). This supports
99
constant-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
1212
requires access to the "previous" pointer and thus can only be
1313
performed 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
1616
accessible 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
1818
before use. Its interior fields are opaque and should not be accessed
1919
by user code.
2020

2121
The 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
2323
return 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
2727
general, it is expected to be allocated/controlled by the user,
2828
usually embedded within a struct which is to be added to the list.
2929
The 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
3131
containing 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

3535
Lists 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`,
3838
which 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
4040
predecessor. These operations are all constant time.
4141

4242
Convenience 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
4545
subset 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)
4747
for a given node and remove it if present.
4848

4949
Finally the slist implementation provides a set of "for each" macros
5050
that 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`
5252
will 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
5454
similarly, but has a more complicated implementation that requires an
5555
extra scratch variable for storage and allows the user to delete the
5656
iterated 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
5959
variable of a type that matches the user's container struct and not
6060
the 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
6262
node and all its successors only, without inspecting the earlier part
6363
of the list.
6464

6565
Single-linked List Internals
6666
----------------------------
6767

6868
The 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
7171
single "next" pointer.
7272

7373
.. figure:: slist.png
@@ -101,14 +101,14 @@ Only one such variant, sflist, exists in Zephyr at the moment.
101101
Flagged 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
105105
template API. With the exception of symbol naming ("sflist" instead
106106
of "slist") and the additional API described next, it operates in all
107107
ways identically to the slist API.
108108

109109
It 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`.
112112
Internally, the flags are stored unioned with the bottom bits of the
113113
next pointer and incur no SRAM storage overhead when compared with the
114114
simpler slist code.

include/sys/dlist.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
extern "C" {
2929
#endif
3030

31+
/**
32+
* @defgroup doubly-linked-list_apis Doubly-linked list
33+
* @ingroup datastructure_apis
34+
* @{
35+
*/
36+
3137
struct _dnode {
3238
union {
3339
struct _dnode *head; /* ptr to head of list (sys_dlist_t) */
@@ -42,11 +48,6 @@ struct _dnode {
4248
typedef struct _dnode sys_dlist_t;
4349
typedef struct _dnode sys_dnode_t;
4450

45-
/**
46-
* @defgroup doubly-linked-list_apis Doubly-linked list
47-
* @ingroup datastructure_apis
48-
* @{
49-
*/
5051

5152
/**
5253
* @brief Provide the primitive to iterate on a list

0 commit comments

Comments
 (0)