diff options
Diffstat (limited to 'coverage-report/ccan/list/list.h.gcov.html')
-rw-r--r-- | coverage-report/ccan/list/list.h.gcov.html | 668 |
1 files changed, 668 insertions, 0 deletions
diff --git a/coverage-report/ccan/list/list.h.gcov.html b/coverage-report/ccan/list/list.h.gcov.html new file mode 100644 index 0000000..342e63f --- /dev/null +++ b/coverage-report/ccan/list/list.h.gcov.html @@ -0,0 +1,668 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html lang="en"> + +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>LCOV - skiboot.info - ccan/list/list.h</title> + <link rel="stylesheet" type="text/css" href="../../gcov.css"> +</head> + +<body> + + <table width="100%" border=0 cellspacing=0 cellpadding=0> + <tr><td class="title">LCOV - code coverage report</td></tr> + <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr> + + <tr> + <td width="100%"> + <table cellpadding=1 border=0 width="100%"> + <tr> + <td width="10%" class="headerItem">Current view:</td> + <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">ccan/list</a> - list.h<span style="font-size: 80%;"> (source / <a href="list.h.func-sort-c.html">functions</a>)</span></td> + <td width="5%"></td> + <td width="15%"></td> + <td width="10%" class="headerCovTableHead">Hit</td> + <td width="10%" class="headerCovTableHead">Total</td> + <td width="15%" class="headerCovTableHead">Coverage</td> + </tr> + <tr> + <td class="headerItem">Test:</td> + <td class="headerValue">skiboot.info</td> + <td></td> + <td class="headerItem">Lines:</td> + <td class="headerCovTableEntry">72</td> + <td class="headerCovTableEntry">72</td> + <td class="headerCovTableEntryHi">100.0 %</td> + </tr> + <tr> + <td class="headerItem">Date:</td> + <td class="headerValue">2021-05-13 12:18:09</td> + <td></td> + <td class="headerItem">Functions:</td> + <td class="headerCovTableEntry">15</td> + <td class="headerCovTableEntry">15</td> + <td class="headerCovTableEntryHi">100.0 %</td> + </tr> + <tr> + <td></td> + <td></td> + <td></td> + <td class="headerItem">Branches:</td> + <td class="headerCovTableEntry">0</td> + <td class="headerCovTableEntry">0</td> + <td class="headerCovTableEntryHi">-</td> + </tr> + <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr> + </table> + </td> + </tr> + + <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr> + </table> + + <table cellpadding=0 cellspacing=0 border=0> + <tr> + <td><br></td> + </tr> + <tr> + <td> +<pre class="sourceHeading"> Branch data Line data Source code</pre> +<pre class="source"> +<a name="1"><span class="lineNum"> 1 </span> : : /* Licensed under BSD-MIT - see LICENSE file for details */</a> +<a name="2"><span class="lineNum"> 2 </span> : : #ifndef CCAN_LIST_H</a> +<a name="3"><span class="lineNum"> 3 </span> : : #define CCAN_LIST_H</a> +<a name="4"><span class="lineNum"> 4 </span> : : #include <stdbool.h></a> +<a name="5"><span class="lineNum"> 5 </span> : : #include <assert.h></a> +<a name="6"><span class="lineNum"> 6 </span> : : #include <ccan/container_of/container_of.h></a> +<a name="7"><span class="lineNum"> 7 </span> : : #include <ccan/check_type/check_type.h></a> +<a name="8"><span class="lineNum"> 8 </span> : : </a> +<a name="9"><span class="lineNum"> 9 </span> : : /**</a> +<a name="10"><span class="lineNum"> 10 </span> : : * struct list_node - an entry in a doubly-linked list</a> +<a name="11"><span class="lineNum"> 11 </span> : : * @next: next entry (self if empty)</a> +<a name="12"><span class="lineNum"> 12 </span> : : * @prev: previous entry (self if empty)</a> +<a name="13"><span class="lineNum"> 13 </span> : : *</a> +<a name="14"><span class="lineNum"> 14 </span> : : * This is used as an entry in a linked list.</a> +<a name="15"><span class="lineNum"> 15 </span> : : * Example:</a> +<a name="16"><span class="lineNum"> 16 </span> : : * struct child {</a> +<a name="17"><span class="lineNum"> 17 </span> : : * const char *name;</a> +<a name="18"><span class="lineNum"> 18 </span> : : * // Linked list of all us children.</a> +<a name="19"><span class="lineNum"> 19 </span> : : * struct list_node list;</a> +<a name="20"><span class="lineNum"> 20 </span> : : * };</a> +<a name="21"><span class="lineNum"> 21 </span> : : */</a> +<a name="22"><span class="lineNum"> 22 </span> : : struct list_node</a> +<a name="23"><span class="lineNum"> 23 </span> : : {</a> +<a name="24"><span class="lineNum"> 24 </span> : : struct list_node *next, *prev;</a> +<a name="25"><span class="lineNum"> 25 </span> : : };</a> +<a name="26"><span class="lineNum"> 26 </span> : : </a> +<a name="27"><span class="lineNum"> 27 </span> : : /**</a> +<a name="28"><span class="lineNum"> 28 </span> : : * struct list_head - the head of a doubly-linked list</a> +<a name="29"><span class="lineNum"> 29 </span> : : * @h: the list_head (containing next and prev pointers)</a> +<a name="30"><span class="lineNum"> 30 </span> : : *</a> +<a name="31"><span class="lineNum"> 31 </span> : : * This is used as the head of a linked list.</a> +<a name="32"><span class="lineNum"> 32 </span> : : * Example:</a> +<a name="33"><span class="lineNum"> 33 </span> : : * struct parent {</a> +<a name="34"><span class="lineNum"> 34 </span> : : * const char *name;</a> +<a name="35"><span class="lineNum"> 35 </span> : : * struct list_head children;</a> +<a name="36"><span class="lineNum"> 36 </span> : : * unsigned int num_children;</a> +<a name="37"><span class="lineNum"> 37 </span> : : * };</a> +<a name="38"><span class="lineNum"> 38 </span> : : */</a> +<a name="39"><span class="lineNum"> 39 </span> : : struct list_head</a> +<a name="40"><span class="lineNum"> 40 </span> : : {</a> +<a name="41"><span class="lineNum"> 41 </span> : : struct list_node n;</a> +<a name="42"><span class="lineNum"> 42 </span> : : };</a> +<a name="43"><span class="lineNum"> 43 </span> : : </a> +<a name="44"><span class="lineNum"> 44 </span> : : /**</a> +<a name="45"><span class="lineNum"> 45 </span> : : * list_check - check head of a list for consistency</a> +<a name="46"><span class="lineNum"> 46 </span> : : * @h: the list_head</a> +<a name="47"><span class="lineNum"> 47 </span> : : * @abortstr: the location to print on aborting, or NULL.</a> +<a name="48"><span class="lineNum"> 48 </span> : : *</a> +<a name="49"><span class="lineNum"> 49 </span> : : * Because list_nodes have redundant information, consistency checking between</a> +<a name="50"><span class="lineNum"> 50 </span> : : * the back and forward links can be done. This is useful as a debugging check.</a> +<a name="51"><span class="lineNum"> 51 </span> : : * If @abortstr is non-NULL, that will be printed in a diagnostic if the list</a> +<a name="52"><span class="lineNum"> 52 </span> : : * is inconsistent, and the function will abort.</a> +<a name="53"><span class="lineNum"> 53 </span> : : *</a> +<a name="54"><span class="lineNum"> 54 </span> : : * Returns the list head if the list is consistent, NULL if not (it</a> +<a name="55"><span class="lineNum"> 55 </span> : : * can never return NULL if @abortstr is set).</a> +<a name="56"><span class="lineNum"> 56 </span> : : *</a> +<a name="57"><span class="lineNum"> 57 </span> : : * See also: list_check_node()</a> +<a name="58"><span class="lineNum"> 58 </span> : : *</a> +<a name="59"><span class="lineNum"> 59 </span> : : * Example:</a> +<a name="60"><span class="lineNum"> 60 </span> : : * static void dump_parent(struct parent *p)</a> +<a name="61"><span class="lineNum"> 61 </span> : : * {</a> +<a name="62"><span class="lineNum"> 62 </span> : : * struct child *c;</a> +<a name="63"><span class="lineNum"> 63 </span> : : *</a> +<a name="64"><span class="lineNum"> 64 </span> : : * printf("%s (%u children):\n", p->name, p->num_children);</a> +<a name="65"><span class="lineNum"> 65 </span> : : * list_check(&p->children, "bad child list");</a> +<a name="66"><span class="lineNum"> 66 </span> : : * list_for_each(&p->children, c, list)</a> +<a name="67"><span class="lineNum"> 67 </span> : : * printf(" -> %s\n", c->name);</a> +<a name="68"><span class="lineNum"> 68 </span> : : * }</a> +<a name="69"><span class="lineNum"> 69 </span> : : */</a> +<a name="70"><span class="lineNum"> 70 </span> : : struct list_head *list_check(const struct list_head *h, const char *abortstr);</a> +<a name="71"><span class="lineNum"> 71 </span> : : </a> +<a name="72"><span class="lineNum"> 72 </span> : : /**</a> +<a name="73"><span class="lineNum"> 73 </span> : : * list_check_node - check node of a list for consistency</a> +<a name="74"><span class="lineNum"> 74 </span> : : * @n: the list_node</a> +<a name="75"><span class="lineNum"> 75 </span> : : * @abortstr: the location to print on aborting, or NULL.</a> +<a name="76"><span class="lineNum"> 76 </span> : : *</a> +<a name="77"><span class="lineNum"> 77 </span> : : * Check consistency of the list node is in (it must be in one).</a> +<a name="78"><span class="lineNum"> 78 </span> : : *</a> +<a name="79"><span class="lineNum"> 79 </span> : : * See also: list_check()</a> +<a name="80"><span class="lineNum"> 80 </span> : : *</a> +<a name="81"><span class="lineNum"> 81 </span> : : * Example:</a> +<a name="82"><span class="lineNum"> 82 </span> : : * static void dump_child(const struct child *c)</a> +<a name="83"><span class="lineNum"> 83 </span> : : * {</a> +<a name="84"><span class="lineNum"> 84 </span> : : * list_check_node(&c->list, "bad child list");</a> +<a name="85"><span class="lineNum"> 85 </span> : : * printf("%s\n", c->name);</a> +<a name="86"><span class="lineNum"> 86 </span> : : * }</a> +<a name="87"><span class="lineNum"> 87 </span> : : */</a> +<a name="88"><span class="lineNum"> 88 </span> : : struct list_node *list_check_node(const struct list_node *n,</a> +<a name="89"><span class="lineNum"> 89 </span> : : const char *abortstr);</a> +<a name="90"><span class="lineNum"> 90 </span> : : </a> +<a name="91"><span class="lineNum"> 91 </span> : : #ifdef CCAN_LIST_DEBUG</a> +<a name="92"><span class="lineNum"> 92 </span> : : #define list_debug(h) list_check((h), __func__)</a> +<a name="93"><span class="lineNum"> 93 </span> : : #define list_debug_node(n) list_check_node((n), __func__)</a> +<a name="94"><span class="lineNum"> 94 </span> : : #else</a> +<a name="95"><span class="lineNum"> 95 </span> : : #define list_debug(h) (h)</a> +<a name="96"><span class="lineNum"> 96 </span> : : #define list_debug_node(n) (n)</a> +<a name="97"><span class="lineNum"> 97 </span> : : #endif</a> +<a name="98"><span class="lineNum"> 98 </span> : : </a> +<a name="99"><span class="lineNum"> 99 </span> : : /**</a> +<a name="100"><span class="lineNum"> 100 </span> : : * LIST_HEAD_INIT - initializer for an empty list_head</a> +<a name="101"><span class="lineNum"> 101 </span> : : * @name: the name of the list.</a> +<a name="102"><span class="lineNum"> 102 </span> : : *</a> +<a name="103"><span class="lineNum"> 103 </span> : : * Explicit initializer for an empty list.</a> +<a name="104"><span class="lineNum"> 104 </span> : : *</a> +<a name="105"><span class="lineNum"> 105 </span> : : * See also:</a> +<a name="106"><span class="lineNum"> 106 </span> : : * LIST_HEAD, list_head_init()</a> +<a name="107"><span class="lineNum"> 107 </span> : : *</a> +<a name="108"><span class="lineNum"> 108 </span> : : * Example:</a> +<a name="109"><span class="lineNum"> 109 </span> : : * static struct list_head my_list = LIST_HEAD_INIT(my_list);</a> +<a name="110"><span class="lineNum"> 110 </span> : : */</a> +<a name="111"><span class="lineNum"> 111 </span> : : #define LIST_HEAD_INIT(name) { { &name.n, &name.n } }</a> +<a name="112"><span class="lineNum"> 112 </span> : : </a> +<a name="113"><span class="lineNum"> 113 </span> : : /**</a> +<a name="114"><span class="lineNum"> 114 </span> : : * LIST_HEAD - define and initialize an empty list_head</a> +<a name="115"><span class="lineNum"> 115 </span> : : * @name: the name of the list.</a> +<a name="116"><span class="lineNum"> 116 </span> : : *</a> +<a name="117"><span class="lineNum"> 117 </span> : : * The LIST_HEAD macro defines a list_head and initializes it to an empty</a> +<a name="118"><span class="lineNum"> 118 </span> : : * list. It can be prepended by "static" to define a static list_head.</a> +<a name="119"><span class="lineNum"> 119 </span> : : *</a> +<a name="120"><span class="lineNum"> 120 </span> : : * See also:</a> +<a name="121"><span class="lineNum"> 121 </span> : : * LIST_HEAD_INIT, list_head_init()</a> +<a name="122"><span class="lineNum"> 122 </span> : : *</a> +<a name="123"><span class="lineNum"> 123 </span> : : * Example:</a> +<a name="124"><span class="lineNum"> 124 </span> : : * static LIST_HEAD(my_global_list);</a> +<a name="125"><span class="lineNum"> 125 </span> : : */</a> +<a name="126"><span class="lineNum"> 126 </span> : : #define LIST_HEAD(name) \</a> +<a name="127"><span class="lineNum"> 127 </span> : : struct list_head name = LIST_HEAD_INIT(name)</a> +<a name="128"><span class="lineNum"> 128 </span> : : </a> +<a name="129"><span class="lineNum"> 129 </span> : : /**</a> +<a name="130"><span class="lineNum"> 130 </span> : : * list_head_init - initialize a list_head</a> +<a name="131"><span class="lineNum"> 131 </span> : : * @h: the list_head to set to the empty list</a> +<a name="132"><span class="lineNum"> 132 </span> : : *</a> +<a name="133"><span class="lineNum"> 133 </span> : : * Example:</a> +<a name="134"><span class="lineNum"> 134 </span> : : * ...</a> +<a name="135"><span class="lineNum"> 135 </span> : : * struct parent *parent = malloc(sizeof(*parent));</a> +<a name="136"><span class="lineNum"> 136 </span> : : *</a> +<a name="137"><span class="lineNum"> 137 </span> : : * list_head_init(&parent->children);</a> +<a name="138"><span class="lineNum"> 138 </span> : : * parent->num_children = 0;</a> +<a name="139"><span class="lineNum"> 139 </span> : : */</a> +<a name="140"><span class="lineNum"> 140 </span> :<span class="lineCov"> 1866 : static inline void list_head_init(struct list_head *h)</span></a> +<a name="141"><span class="lineNum"> 141 </span> : : {</a> +<a name="142"><span class="lineNum"> 142 </span> :<span class="lineCov"> 1866 : h->n.next = h->n.prev = &h->n;</span></a> +<a name="143"><span class="lineNum"> 143 </span> :<span class="lineCov"> 1866 : }</span></a> +<a name="144"><span class="lineNum"> 144 </span> : : </a> +<a name="145"><span class="lineNum"> 145 </span> : : /**</a> +<a name="146"><span class="lineNum"> 146 </span> : : * list_add - add an entry at the start of a linked list.</a> +<a name="147"><span class="lineNum"> 147 </span> : : * @h: the list_head to add the node to</a> +<a name="148"><span class="lineNum"> 148 </span> : : * @n: the list_node to add to the list.</a> +<a name="149"><span class="lineNum"> 149 </span> : : *</a> +<a name="150"><span class="lineNum"> 150 </span> : : * The list_node does not need to be initialized; it will be overwritten.</a> +<a name="151"><span class="lineNum"> 151 </span> : : * Example:</a> +<a name="152"><span class="lineNum"> 152 </span> : : * struct child *child = malloc(sizeof(*child));</a> +<a name="153"><span class="lineNum"> 153 </span> : : *</a> +<a name="154"><span class="lineNum"> 154 </span> : : * child->name = "marvin";</a> +<a name="155"><span class="lineNum"> 155 </span> : : * list_add(&parent->children, &child->list);</a> +<a name="156"><span class="lineNum"> 156 </span> : : * parent->num_children++;</a> +<a name="157"><span class="lineNum"> 157 </span> : : */</a> +<a name="158"><span class="lineNum"> 158 </span> :<span class="lineCov"> 14471 : static inline void list_add(struct list_head *h, struct list_node *n)</span></a> +<a name="159"><span class="lineNum"> 159 </span> : : {</a> +<a name="160"><span class="lineNum"> 160 </span> :<span class="lineCov"> 14471 : n->next = h->n.next;</span></a> +<a name="161"><span class="lineNum"> 161 </span> :<span class="lineCov"> 14471 : n->prev = &h->n;</span></a> +<a name="162"><span class="lineNum"> 162 </span> :<span class="lineCov"> 14471 : h->n.next->prev = n;</span></a> +<a name="163"><span class="lineNum"> 163 </span> :<span class="lineCov"> 14471 : h->n.next = n;</span></a> +<a name="164"><span class="lineNum"> 164 </span> :<span class="lineCov"> 14471 : (void)list_debug(h);</span></a> +<a name="165"><span class="lineNum"> 165 </span> :<span class="lineCov"> 14471 : }</span></a> +<a name="166"><span class="lineNum"> 166 </span> : : </a> +<a name="167"><span class="lineNum"> 167 </span> : : /**</a> +<a name="168"><span class="lineNum"> 168 </span> : : * list_add_before - add an entry before another entry.</a> +<a name="169"><span class="lineNum"> 169 </span> : : * @h: the list_head to add the node to (we use it for debug purposes, can be NULL)</a> +<a name="170"><span class="lineNum"> 170 </span> : : * @n: the list_node to add to the list.</a> +<a name="171"><span class="lineNum"> 171 </span> : : * @p: the list_node of the other entry</a> +<a name="172"><span class="lineNum"> 172 </span> : : *</a> +<a name="173"><span class="lineNum"> 173 </span> : : * The list_node does not need to be initialized; it will be overwritten.</a> +<a name="174"><span class="lineNum"> 174 </span> : : */</a> +<a name="175"><span class="lineNum"> 175 </span> :<span class="lineCov"> 948 : static inline void list_add_before(struct list_head *h, struct list_node *n,</span></a> +<a name="176"><span class="lineNum"> 176 </span> : : struct list_node *p)</a> +<a name="177"><span class="lineNum"> 177 </span> : : {</a> +<a name="178"><span class="lineNum"> 178 </span> :<span class="lineCov"> 948 : n->next = p;</span></a> +<a name="179"><span class="lineNum"> 179 </span> :<span class="lineCov"> 948 : n->prev = p->prev;</span></a> +<a name="180"><span class="lineNum"> 180 </span> :<span class="lineCov"> 948 : p->prev = n;</span></a> +<a name="181"><span class="lineNum"> 181 </span> :<span class="lineCov"> 948 : n->prev->next = n;</span></a> +<a name="182"><span class="lineNum"> 182 </span> :<span class="lineCov"> 948 : if (h)</span></a> +<a name="183"><span class="lineNum"> 183 </span> :<span class="lineCov"> 948 : (void)list_debug(h);</span></a> +<a name="184"><span class="lineNum"> 184 </span> :<span class="lineCov"> 948 : }</span></a> +<a name="185"><span class="lineNum"> 185 </span> : : </a> +<a name="186"><span class="lineNum"> 186 </span> : : /**</a> +<a name="187"><span class="lineNum"> 187 </span> : : * list_add_after - add an entry after another entry.</a> +<a name="188"><span class="lineNum"> 188 </span> : : * @h: the list_head to add the node to (we use it for debug purposes, can be NULL)</a> +<a name="189"><span class="lineNum"> 189 </span> : : * @n: the list_node to add to the list.</a> +<a name="190"><span class="lineNum"> 190 </span> : : * @p: the list_node of the other entry</a> +<a name="191"><span class="lineNum"> 191 </span> : : *</a> +<a name="192"><span class="lineNum"> 192 </span> : : * The list_node does not need to be initialized; it will be overwritten.</a> +<a name="193"><span class="lineNum"> 193 </span> : : */</a> +<a name="194"><span class="lineNum"> 194 </span> :<span class="lineCov"> 40 : static inline void list_add_after(struct list_head *h, struct list_node *n,</span></a> +<a name="195"><span class="lineNum"> 195 </span> : : struct list_node *p)</a> +<a name="196"><span class="lineNum"> 196 </span> : : {</a> +<a name="197"><span class="lineNum"> 197 </span> :<span class="lineCov"> 40 : n->next = p->next;</span></a> +<a name="198"><span class="lineNum"> 198 </span> :<span class="lineCov"> 40 : n->prev = p;</span></a> +<a name="199"><span class="lineNum"> 199 </span> :<span class="lineCov"> 40 : p->next = n;</span></a> +<a name="200"><span class="lineNum"> 200 </span> :<span class="lineCov"> 40 : n->next->prev = n;</span></a> +<a name="201"><span class="lineNum"> 201 </span> :<span class="lineCov"> 40 : if (h)</span></a> +<a name="202"><span class="lineNum"> 202 </span> :<span class="lineCov"> 40 : (void)list_debug(h);</span></a> +<a name="203"><span class="lineNum"> 203 </span> :<span class="lineCov"> 40 : }</span></a> +<a name="204"><span class="lineNum"> 204 </span> : : </a> +<a name="205"><span class="lineNum"> 205 </span> : : /**</a> +<a name="206"><span class="lineNum"> 206 </span> : : * list_add_tail - add an entry at the end of a linked list.</a> +<a name="207"><span class="lineNum"> 207 </span> : : * @h: the list_head to add the node to</a> +<a name="208"><span class="lineNum"> 208 </span> : : * @n: the list_node to add to the list.</a> +<a name="209"><span class="lineNum"> 209 </span> : : *</a> +<a name="210"><span class="lineNum"> 210 </span> : : * The list_node does not need to be initialized; it will be overwritten.</a> +<a name="211"><span class="lineNum"> 211 </span> : : * Example:</a> +<a name="212"><span class="lineNum"> 212 </span> : : * list_add_tail(&parent->children, &child->list);</a> +<a name="213"><span class="lineNum"> 213 </span> : : * parent->num_children++;</a> +<a name="214"><span class="lineNum"> 214 </span> : : */</a> +<a name="215"><span class="lineNum"> 215 </span> :<span class="lineCov"> 4901 : static inline void list_add_tail(struct list_head *h, struct list_node *n)</span></a> +<a name="216"><span class="lineNum"> 216 </span> : : {</a> +<a name="217"><span class="lineNum"> 217 </span> :<span class="lineCov"> 4901 : n->next = &h->n;</span></a> +<a name="218"><span class="lineNum"> 218 </span> :<span class="lineCov"> 4901 : n->prev = h->n.prev;</span></a> +<a name="219"><span class="lineNum"> 219 </span> :<span class="lineCov"> 4901 : h->n.prev->next = n;</span></a> +<a name="220"><span class="lineNum"> 220 </span> :<span class="lineCov"> 4901 : h->n.prev = n;</span></a> +<a name="221"><span class="lineNum"> 221 </span> :<span class="lineCov"> 4901 : (void)list_debug(h);</span></a> +<a name="222"><span class="lineNum"> 222 </span> :<span class="lineCov"> 4901 : }</span></a> +<a name="223"><span class="lineNum"> 223 </span> : : </a> +<a name="224"><span class="lineNum"> 224 </span> : : /**</a> +<a name="225"><span class="lineNum"> 225 </span> : : * list_empty - is a list empty?</a> +<a name="226"><span class="lineNum"> 226 </span> : : * @h: the list_head</a> +<a name="227"><span class="lineNum"> 227 </span> : : *</a> +<a name="228"><span class="lineNum"> 228 </span> : : * If the list is empty, returns true.</a> +<a name="229"><span class="lineNum"> 229 </span> : : *</a> +<a name="230"><span class="lineNum"> 230 </span> : : * Example:</a> +<a name="231"><span class="lineNum"> 231 </span> : : * assert(list_empty(&parent->children) == (parent->num_children == 0));</a> +<a name="232"><span class="lineNum"> 232 </span> : : */</a> +<a name="233"><span class="lineNum"> 233 </span> :<span class="lineCov"> 163970 : static inline bool list_empty(const struct list_head *h)</span></a> +<a name="234"><span class="lineNum"> 234 </span> : : {</a> +<a name="235"><span class="lineNum"> 235 </span> :<span class="lineCov"> 163970 : (void)list_debug(h);</span></a> +<a name="236"><span class="lineNum"> 236 </span> :<span class="lineCov"> 163970 : return h->n.next == &h->n;</span></a> +<a name="237"><span class="lineNum"> 237 </span> : : }</a> +<a name="238"><span class="lineNum"> 238 </span> : : </a> +<a name="239"><span class="lineNum"> 239 </span> : : /**</a> +<a name="240"><span class="lineNum"> 240 </span> : : * list_empty_nocheck - is a list empty?</a> +<a name="241"><span class="lineNum"> 241 </span> : : * @h: the list_head</a> +<a name="242"><span class="lineNum"> 242 </span> : : *</a> +<a name="243"><span class="lineNum"> 243 </span> : : * If the list is empty, returns true. This doesn't perform any</a> +<a name="244"><span class="lineNum"> 244 </span> : : * debug check for list consistency, so it can be called without</a> +<a name="245"><span class="lineNum"> 245 </span> : : * locks, racing with the list being modified. This is ok for</a> +<a name="246"><span class="lineNum"> 246 </span> : : * checks where an incorrect result is not an issue (optimized</a> +<a name="247"><span class="lineNum"> 247 </span> : : * bail out path for example).</a> +<a name="248"><span class="lineNum"> 248 </span> : : */</a> +<a name="249"><span class="lineNum"> 249 </span> :<span class="lineCov"> 130932 : static inline bool list_empty_nocheck(const struct list_head *h)</span></a> +<a name="250"><span class="lineNum"> 250 </span> : : {</a> +<a name="251"><span class="lineNum"> 251 </span> :<span class="lineCov"> 130932 : return h->n.next == &h->n;</span></a> +<a name="252"><span class="lineNum"> 252 </span> : : }</a> +<a name="253"><span class="lineNum"> 253 </span> : : </a> +<a name="254"><span class="lineNum"> 254 </span> : : /**</a> +<a name="255"><span class="lineNum"> 255 </span> : : * list_del - delete an entry from an (unknown) linked list.</a> +<a name="256"><span class="lineNum"> 256 </span> : : * @n: the list_node to delete from the list.</a> +<a name="257"><span class="lineNum"> 257 </span> : : *</a> +<a name="258"><span class="lineNum"> 258 </span> : : * Note that this leaves @n in an undefined state; it can be added to</a> +<a name="259"><span class="lineNum"> 259 </span> : : * another list, but not deleted again.</a> +<a name="260"><span class="lineNum"> 260 </span> : : *</a> +<a name="261"><span class="lineNum"> 261 </span> : : * See also:</a> +<a name="262"><span class="lineNum"> 262 </span> : : * list_del_from()</a> +<a name="263"><span class="lineNum"> 263 </span> : : *</a> +<a name="264"><span class="lineNum"> 264 </span> : : * Example:</a> +<a name="265"><span class="lineNum"> 265 </span> : : * list_del(&child->list);</a> +<a name="266"><span class="lineNum"> 266 </span> : : * parent->num_children--;</a> +<a name="267"><span class="lineNum"> 267 </span> : : */</a> +<a name="268"><span class="lineNum"> 268 </span> :<span class="lineCov"> 20070 : static inline void list_del(struct list_node *n)</span></a> +<a name="269"><span class="lineNum"> 269 </span> : : {</a> +<a name="270"><span class="lineNum"> 270 </span> :<span class="lineCov"> 20070 : (void)list_debug_node(n);</span></a> +<a name="271"><span class="lineNum"> 271 </span> :<span class="lineCov"> 20070 : n->next->prev = n->prev;</span></a> +<a name="272"><span class="lineNum"> 272 </span> :<span class="lineCov"> 20070 : n->prev->next = n->next;</span></a> +<a name="273"><span class="lineNum"> 273 </span> : : #ifdef CCAN_LIST_DEBUG</a> +<a name="274"><span class="lineNum"> 274 </span> : : /* Catch use-after-del. */</a> +<a name="275"><span class="lineNum"> 275 </span> :<span class="lineCov"> 20070 : n->next = n->prev = NULL;</span></a> +<a name="276"><span class="lineNum"> 276 </span> : : #endif</a> +<a name="277"><span class="lineNum"> 277 </span> :<span class="lineCov"> 20070 : }</span></a> +<a name="278"><span class="lineNum"> 278 </span> : : </a> +<a name="279"><span class="lineNum"> 279 </span> : : /**</a> +<a name="280"><span class="lineNum"> 280 </span> : : * list_del_from - delete an entry from a known linked list.</a> +<a name="281"><span class="lineNum"> 281 </span> : : * @h: the list_head the node is in.</a> +<a name="282"><span class="lineNum"> 282 </span> : : * @n: the list_node to delete from the list.</a> +<a name="283"><span class="lineNum"> 283 </span> : : *</a> +<a name="284"><span class="lineNum"> 284 </span> : : * This explicitly indicates which list a node is expected to be in,</a> +<a name="285"><span class="lineNum"> 285 </span> : : * which is better documentation and can catch more bugs.</a> +<a name="286"><span class="lineNum"> 286 </span> : : *</a> +<a name="287"><span class="lineNum"> 287 </span> : : * See also: list_del()</a> +<a name="288"><span class="lineNum"> 288 </span> : : *</a> +<a name="289"><span class="lineNum"> 289 </span> : : * Example:</a> +<a name="290"><span class="lineNum"> 290 </span> : : * list_del_from(&parent->children, &child->list);</a> +<a name="291"><span class="lineNum"> 291 </span> : : * parent->num_children--;</a> +<a name="292"><span class="lineNum"> 292 </span> : : */</a> +<a name="293"><span class="lineNum"> 293 </span> :<span class="lineCov"> 15170 : static inline void list_del_from(struct list_head *h, struct list_node *n)</span></a> +<a name="294"><span class="lineNum"> 294 </span> : : {</a> +<a name="295"><span class="lineNum"> 295 </span> : : #ifdef CCAN_LIST_DEBUG</a> +<a name="296"><span class="lineNum"> 296 </span> : : {</a> +<a name="297"><span class="lineNum"> 297 </span> : : /* Thorough check: make sure it was in list! */</a> +<a name="298"><span class="lineNum"> 298 </span> : : struct list_node *i;</a> +<a name="299"><span class="lineNum"> 299 </span> :<span class="lineCov"> 16867 : for (i = h->n.next; i != n; i = i->next)</span></a> +<a name="300"><span class="lineNum"> 300 </span> :<span class="lineCov"> 1697 : assert(i != &h->n);</span></a> +<a name="301"><span class="lineNum"> 301 </span> : : }</a> +<a name="302"><span class="lineNum"> 302 </span> : : #endif /* CCAN_LIST_DEBUG */</a> +<a name="303"><span class="lineNum"> 303 </span> : : </a> +<a name="304"><span class="lineNum"> 304 </span> : : /* Quick test that catches a surprising number of bugs. */</a> +<a name="305"><span class="lineNum"> 305 </span> :<span class="lineCov"> 15170 : assert(!list_empty(h));</span></a> +<a name="306"><span class="lineNum"> 306 </span> :<span class="lineCov"> 15170 : list_del(n);</span></a> +<a name="307"><span class="lineNum"> 307 </span> :<span class="lineCov"> 15170 : }</span></a> +<a name="308"><span class="lineNum"> 308 </span> : : </a> +<a name="309"><span class="lineNum"> 309 </span> : : /**</a> +<a name="310"><span class="lineNum"> 310 </span> : : * list_entry - convert a list_node back into the structure containing it.</a> +<a name="311"><span class="lineNum"> 311 </span> : : * @n: the list_node</a> +<a name="312"><span class="lineNum"> 312 </span> : : * @type: the type of the entry</a> +<a name="313"><span class="lineNum"> 313 </span> : : * @member: the list_node member of the type</a> +<a name="314"><span class="lineNum"> 314 </span> : : *</a> +<a name="315"><span class="lineNum"> 315 </span> : : * Example:</a> +<a name="316"><span class="lineNum"> 316 </span> : : * // First list entry is children.next; convert back to child.</a> +<a name="317"><span class="lineNum"> 317 </span> : : * child = list_entry(parent->children.n.next, struct child, list);</a> +<a name="318"><span class="lineNum"> 318 </span> : : *</a> +<a name="319"><span class="lineNum"> 319 </span> : : * See Also:</a> +<a name="320"><span class="lineNum"> 320 </span> : : * list_top(), list_for_each()</a> +<a name="321"><span class="lineNum"> 321 </span> : : */</a> +<a name="322"><span class="lineNum"> 322 </span> : : #define list_entry(n, type, member) container_of(n, type, member)</a> +<a name="323"><span class="lineNum"> 323 </span> : : </a> +<a name="324"><span class="lineNum"> 324 </span> : : /**</a> +<a name="325"><span class="lineNum"> 325 </span> : : * list_top - get the first entry in a list</a> +<a name="326"><span class="lineNum"> 326 </span> : : * @h: the list_head</a> +<a name="327"><span class="lineNum"> 327 </span> : : * @type: the type of the entry</a> +<a name="328"><span class="lineNum"> 328 </span> : : * @member: the list_node member of the type</a> +<a name="329"><span class="lineNum"> 329 </span> : : *</a> +<a name="330"><span class="lineNum"> 330 </span> : : * If the list is empty, returns NULL.</a> +<a name="331"><span class="lineNum"> 331 </span> : : *</a> +<a name="332"><span class="lineNum"> 332 </span> : : * Example:</a> +<a name="333"><span class="lineNum"> 333 </span> : : * struct child *first;</a> +<a name="334"><span class="lineNum"> 334 </span> : : * first = list_top(&parent->children, struct child, list);</a> +<a name="335"><span class="lineNum"> 335 </span> : : * if (!first)</a> +<a name="336"><span class="lineNum"> 336 </span> : : * printf("Empty list!\n");</a> +<a name="337"><span class="lineNum"> 337 </span> : : */</a> +<a name="338"><span class="lineNum"> 338 </span> : : #define list_top(h, type, member) \</a> +<a name="339"><span class="lineNum"> 339 </span> : : ((type *)list_top_((h), list_off_(type, member)))</a> +<a name="340"><span class="lineNum"> 340 </span> : : </a> +<a name="341"><span class="lineNum"> 341 </span> :<span class="lineCov"> 133431 : static inline const void *list_top_(const struct list_head *h, size_t off)</span></a> +<a name="342"><span class="lineNum"> 342 </span> : : {</a> +<a name="343"><span class="lineNum"> 343 </span> :<span class="lineCov"> 133431 : if (list_empty(h))</span></a> +<a name="344"><span class="lineNum"> 344 </span> :<span class="lineCov"> 66360 : return NULL;</span></a> +<a name="345"><span class="lineNum"> 345 </span> :<span class="lineCov"> 67071 : return (const char *)h->n.next - off;</span></a> +<a name="346"><span class="lineNum"> 346 </span> : : }</a> +<a name="347"><span class="lineNum"> 347 </span> : : </a> +<a name="348"><span class="lineNum"> 348 </span> : : /**</a> +<a name="349"><span class="lineNum"> 349 </span> : : * list_pop - get the first entry in a list and dequeue it</a> +<a name="350"><span class="lineNum"> 350 </span> : : * @h: the list_head</a> +<a name="351"><span class="lineNum"> 351 </span> : : * @type: the type of the entry</a> +<a name="352"><span class="lineNum"> 352 </span> : : * @member: the list_node member of the type</a> +<a name="353"><span class="lineNum"> 353 </span> : : */</a> +<a name="354"><span class="lineNum"> 354 </span> : : #define list_pop(h, type, member) \</a> +<a name="355"><span class="lineNum"> 355 </span> : : ((type *)list_pop_((h), list_off_(type, member)))</a> +<a name="356"><span class="lineNum"> 356 </span> :<span class="lineCov"> 5429 : static inline const void *list_pop_(struct list_head *h, size_t off)</span></a> +<a name="357"><span class="lineNum"> 357 </span> : : {</a> +<a name="358"><span class="lineNum"> 358 </span> : : struct list_node *n;</a> +<a name="359"><span class="lineNum"> 359 </span> : : </a> +<a name="360"><span class="lineNum"> 360 </span> :<span class="lineCov"> 5429 : if (list_empty(h))</span></a> +<a name="361"><span class="lineNum"> 361 </span> :<span class="lineCov"> 861 : return NULL;</span></a> +<a name="362"><span class="lineNum"> 362 </span> :<span class="lineCov"> 4568 : n = h->n.next;</span></a> +<a name="363"><span class="lineNum"> 363 </span> :<span class="lineCov"> 4568 : list_del(n);</span></a> +<a name="364"><span class="lineNum"> 364 </span> :<span class="lineCov"> 4568 : return (const char *)n - off;</span></a> +<a name="365"><span class="lineNum"> 365 </span> : : }</a> +<a name="366"><span class="lineNum"> 366 </span> : : </a> +<a name="367"><span class="lineNum"> 367 </span> : : /**</a> +<a name="368"><span class="lineNum"> 368 </span> : : * list_tail - get the last entry in a list</a> +<a name="369"><span class="lineNum"> 369 </span> : : * @h: the list_head</a> +<a name="370"><span class="lineNum"> 370 </span> : : * @type: the type of the entry</a> +<a name="371"><span class="lineNum"> 371 </span> : : * @member: the list_node member of the type</a> +<a name="372"><span class="lineNum"> 372 </span> : : *</a> +<a name="373"><span class="lineNum"> 373 </span> : : * If the list is empty, returns NULL.</a> +<a name="374"><span class="lineNum"> 374 </span> : : *</a> +<a name="375"><span class="lineNum"> 375 </span> : : * Example:</a> +<a name="376"><span class="lineNum"> 376 </span> : : * struct child *last;</a> +<a name="377"><span class="lineNum"> 377 </span> : : * last = list_tail(&parent->children, struct child, list);</a> +<a name="378"><span class="lineNum"> 378 </span> : : * if (!last)</a> +<a name="379"><span class="lineNum"> 379 </span> : : * printf("Empty list!\n");</a> +<a name="380"><span class="lineNum"> 380 </span> : : */</a> +<a name="381"><span class="lineNum"> 381 </span> : : #define list_tail(h, type, member) \</a> +<a name="382"><span class="lineNum"> 382 </span> : : ((type *)list_tail_((h), list_off_(type, member)))</a> +<a name="383"><span class="lineNum"> 383 </span> : : </a> +<a name="384"><span class="lineNum"> 384 </span> :<span class="lineCov"> 217 : static inline const void *list_tail_(const struct list_head *h, size_t off)</span></a> +<a name="385"><span class="lineNum"> 385 </span> : : {</a> +<a name="386"><span class="lineNum"> 386 </span> :<span class="lineCov"> 217 : if (list_empty(h))</span></a> +<a name="387"><span class="lineNum"> 387 </span> :<span class="lineCov"> 144 : return NULL;</span></a> +<a name="388"><span class="lineNum"> 388 </span> :<span class="lineCov"> 73 : return (const char *)h->n.prev - off;</span></a> +<a name="389"><span class="lineNum"> 389 </span> : : }</a> +<a name="390"><span class="lineNum"> 390 </span> : : </a> +<a name="391"><span class="lineNum"> 391 </span> : : /**</a> +<a name="392"><span class="lineNum"> 392 </span> : : * list_for_each - iterate through a list.</a> +<a name="393"><span class="lineNum"> 393 </span> : : * @h: the list_head (warning: evaluated multiple times!)</a> +<a name="394"><span class="lineNum"> 394 </span> : : * @i: the structure containing the list_node</a> +<a name="395"><span class="lineNum"> 395 </span> : : * @member: the list_node member of the structure</a> +<a name="396"><span class="lineNum"> 396 </span> : : *</a> +<a name="397"><span class="lineNum"> 397 </span> : : * This is a convenient wrapper to iterate @i over the entire list. It's</a> +<a name="398"><span class="lineNum"> 398 </span> : : * a for loop, so you can break and continue as normal.</a> +<a name="399"><span class="lineNum"> 399 </span> : : *</a> +<a name="400"><span class="lineNum"> 400 </span> : : * Example:</a> +<a name="401"><span class="lineNum"> 401 </span> : : * list_for_each(&parent->children, child, list)</a> +<a name="402"><span class="lineNum"> 402 </span> : : * printf("Name: %s\n", child->name);</a> +<a name="403"><span class="lineNum"> 403 </span> : : */</a> +<a name="404"><span class="lineNum"> 404 </span> : : #define list_for_each(h, i, member) \</a> +<a name="405"><span class="lineNum"> 405 </span> : : list_for_each_off(h, i, list_off_var_(i, member))</a> +<a name="406"><span class="lineNum"> 406 </span> : : </a> +<a name="407"><span class="lineNum"> 407 </span> : : /**</a> +<a name="408"><span class="lineNum"> 408 </span> : : * list_for_each_rev - iterate through a list backwards.</a> +<a name="409"><span class="lineNum"> 409 </span> : : * @h: the list_head</a> +<a name="410"><span class="lineNum"> 410 </span> : : * @i: the structure containing the list_node</a> +<a name="411"><span class="lineNum"> 411 </span> : : * @member: the list_node member of the structure</a> +<a name="412"><span class="lineNum"> 412 </span> : : *</a> +<a name="413"><span class="lineNum"> 413 </span> : : * This is a convenient wrapper to iterate @i over the entire list. It's</a> +<a name="414"><span class="lineNum"> 414 </span> : : * a for loop, so you can break and continue as normal.</a> +<a name="415"><span class="lineNum"> 415 </span> : : *</a> +<a name="416"><span class="lineNum"> 416 </span> : : * Example:</a> +<a name="417"><span class="lineNum"> 417 </span> : : * list_for_each_rev(&parent->children, child, list)</a> +<a name="418"><span class="lineNum"> 418 </span> : : * printf("Name: %s\n", child->name);</a> +<a name="419"><span class="lineNum"> 419 </span> : : */</a> +<a name="420"><span class="lineNum"> 420 </span> : : #define list_for_each_rev(h, i, member) \</a> +<a name="421"><span class="lineNum"> 421 </span> : : for (i = container_of_var(list_debug(h)->n.prev, i, member); \</a> +<a name="422"><span class="lineNum"> 422 </span> : : &i->member != &(h)->n; \</a> +<a name="423"><span class="lineNum"> 423 </span> : : i = container_of_var(i->member.prev, i, member))</a> +<a name="424"><span class="lineNum"> 424 </span> : : </a> +<a name="425"><span class="lineNum"> 425 </span> : : /**</a> +<a name="426"><span class="lineNum"> 426 </span> : : * list_for_each_safe - iterate through a list, maybe during deletion</a> +<a name="427"><span class="lineNum"> 427 </span> : : * @h: the list_head</a> +<a name="428"><span class="lineNum"> 428 </span> : : * @i: the structure containing the list_node</a> +<a name="429"><span class="lineNum"> 429 </span> : : * @nxt: the structure containing the list_node</a> +<a name="430"><span class="lineNum"> 430 </span> : : * @member: the list_node member of the structure</a> +<a name="431"><span class="lineNum"> 431 </span> : : *</a> +<a name="432"><span class="lineNum"> 432 </span> : : * This is a convenient wrapper to iterate @i over the entire list. It's</a> +<a name="433"><span class="lineNum"> 433 </span> : : * a for loop, so you can break and continue as normal. The extra variable</a> +<a name="434"><span class="lineNum"> 434 </span> : : * @nxt is used to hold the next element, so you can delete @i from the list.</a> +<a name="435"><span class="lineNum"> 435 </span> : : *</a> +<a name="436"><span class="lineNum"> 436 </span> : : * Example:</a> +<a name="437"><span class="lineNum"> 437 </span> : : * struct child *next;</a> +<a name="438"><span class="lineNum"> 438 </span> : : * list_for_each_safe(&parent->children, child, next, list) {</a> +<a name="439"><span class="lineNum"> 439 </span> : : * list_del(&child->list);</a> +<a name="440"><span class="lineNum"> 440 </span> : : * parent->num_children--;</a> +<a name="441"><span class="lineNum"> 441 </span> : : * }</a> +<a name="442"><span class="lineNum"> 442 </span> : : */</a> +<a name="443"><span class="lineNum"> 443 </span> : : #define list_for_each_safe(h, i, nxt, member) \</a> +<a name="444"><span class="lineNum"> 444 </span> : : list_for_each_safe_off(h, i, nxt, list_off_var_(i, member))</a> +<a name="445"><span class="lineNum"> 445 </span> : : </a> +<a name="446"><span class="lineNum"> 446 </span> : : /**</a> +<a name="447"><span class="lineNum"> 447 </span> : : * list_for_each_off - iterate through a list of memory regions.</a> +<a name="448"><span class="lineNum"> 448 </span> : : * @h: the list_head</a> +<a name="449"><span class="lineNum"> 449 </span> : : * @i: the pointer to a memory region which contains list node data.</a> +<a name="450"><span class="lineNum"> 450 </span> : : * @off: offset(relative to @i) at which list node data resides.</a> +<a name="451"><span class="lineNum"> 451 </span> : : *</a> +<a name="452"><span class="lineNum"> 452 </span> : : * This is a low-level wrapper to iterate @i over the entire list, used to</a> +<a name="453"><span class="lineNum"> 453 </span> : : * implement all oher, more high-level, for-each constructs. It's a for loop,</a> +<a name="454"><span class="lineNum"> 454 </span> : : * so you can break and continue as normal.</a> +<a name="455"><span class="lineNum"> 455 </span> : : *</a> +<a name="456"><span class="lineNum"> 456 </span> : : * WARNING! Being the low-level macro that it is, this wrapper doesn't know</a> +<a name="457"><span class="lineNum"> 457 </span> : : * nor care about the type of @i. The only assumtion made is that @i points</a> +<a name="458"><span class="lineNum"> 458 </span> : : * to a chunk of memory that at some @offset, relative to @i, contains a</a> +<a name="459"><span class="lineNum"> 459 </span> : : * properly filled `struct node_list' which in turn contains pointers to</a> +<a name="460"><span class="lineNum"> 460 </span> : : * memory chunks and it's turtles all the way down. With all that in mind</a> +<a name="461"><span class="lineNum"> 461 </span> : : * remember that given the wrong pointer/offset couple this macro will</a> +<a name="462"><span class="lineNum"> 462 </span> : : * happily churn all you memory until SEGFAULT stops it, in other words</a> +<a name="463"><span class="lineNum"> 463 </span> : : * caveat emptor.</a> +<a name="464"><span class="lineNum"> 464 </span> : : *</a> +<a name="465"><span class="lineNum"> 465 </span> : : * It is worth mentioning that one of legitimate use-cases for that wrapper</a> +<a name="466"><span class="lineNum"> 466 </span> : : * is operation on opaque types with known offset for `struct list_node'</a> +<a name="467"><span class="lineNum"> 467 </span> : : * member(preferably 0), because it allows you not to disclose the type of</a> +<a name="468"><span class="lineNum"> 468 </span> : : * @i.</a> +<a name="469"><span class="lineNum"> 469 </span> : : *</a> +<a name="470"><span class="lineNum"> 470 </span> : : * Example:</a> +<a name="471"><span class="lineNum"> 471 </span> : : * list_for_each_off(&parent->children, child,</a> +<a name="472"><span class="lineNum"> 472 </span> : : * offsetof(struct child, list))</a> +<a name="473"><span class="lineNum"> 473 </span> : : * printf("Name: %s\n", child->name);</a> +<a name="474"><span class="lineNum"> 474 </span> : : */</a> +<a name="475"><span class="lineNum"> 475 </span> : : #define list_for_each_off(h, i, off) \</a> +<a name="476"><span class="lineNum"> 476 </span> : : for (i = list_node_to_off_(list_debug(h)->n.next, (off)); \</a> +<a name="477"><span class="lineNum"> 477 </span> : : list_node_from_off_((void *)i, (off)) != &(h)->n; \</a> +<a name="478"><span class="lineNum"> 478 </span> : : i = list_node_to_off_(list_node_from_off_((void *)i, (off))->next, \</a> +<a name="479"><span class="lineNum"> 479 </span> : : (off)))</a> +<a name="480"><span class="lineNum"> 480 </span> : : </a> +<a name="481"><span class="lineNum"> 481 </span> : : /**</a> +<a name="482"><span class="lineNum"> 482 </span> : : * list_for_each_safe_off - iterate through a list of memory regions, maybe</a> +<a name="483"><span class="lineNum"> 483 </span> : : * during deletion</a> +<a name="484"><span class="lineNum"> 484 </span> : : * @h: the list_head</a> +<a name="485"><span class="lineNum"> 485 </span> : : * @i: the pointer to a memory region which contains list node data.</a> +<a name="486"><span class="lineNum"> 486 </span> : : * @nxt: the structure containing the list_node</a> +<a name="487"><span class="lineNum"> 487 </span> : : * @off: offset(relative to @i) at which list node data resides.</a> +<a name="488"><span class="lineNum"> 488 </span> : : *</a> +<a name="489"><span class="lineNum"> 489 </span> : : * For details see `list_for_each_off' and `list_for_each_safe'</a> +<a name="490"><span class="lineNum"> 490 </span> : : * descriptions.</a> +<a name="491"><span class="lineNum"> 491 </span> : : *</a> +<a name="492"><span class="lineNum"> 492 </span> : : * Example:</a> +<a name="493"><span class="lineNum"> 493 </span> : : * list_for_each_safe_off(&parent->children, child,</a> +<a name="494"><span class="lineNum"> 494 </span> : : * next, offsetof(struct child, list))</a> +<a name="495"><span class="lineNum"> 495 </span> : : * printf("Name: %s\n", child->name);</a> +<a name="496"><span class="lineNum"> 496 </span> : : */</a> +<a name="497"><span class="lineNum"> 497 </span> : : #define list_for_each_safe_off(h, i, nxt, off) \</a> +<a name="498"><span class="lineNum"> 498 </span> : : for (i = list_node_to_off_(list_debug(h)->n.next, (off)), \</a> +<a name="499"><span class="lineNum"> 499 </span> : : nxt = list_node_to_off_(list_node_from_off_(i, (off))->next, \</a> +<a name="500"><span class="lineNum"> 500 </span> : : (off)); \</a> +<a name="501"><span class="lineNum"> 501 </span> : : list_node_from_off_(i, (off)) != &(h)->n; \</a> +<a name="502"><span class="lineNum"> 502 </span> : : i = nxt, \</a> +<a name="503"><span class="lineNum"> 503 </span> : : nxt = list_node_to_off_(list_node_from_off_(i, (off))->next, \</a> +<a name="504"><span class="lineNum"> 504 </span> : : (off)))</a> +<a name="505"><span class="lineNum"> 505 </span> : : </a> +<a name="506"><span class="lineNum"> 506 </span> : : </a> +<a name="507"><span class="lineNum"> 507 </span> : : /* Other -off variants. */</a> +<a name="508"><span class="lineNum"> 508 </span> : : #define list_entry_off(n, type, off) \</a> +<a name="509"><span class="lineNum"> 509 </span> : : ((type *)list_node_from_off_((n), (off)))</a> +<a name="510"><span class="lineNum"> 510 </span> : : </a> +<a name="511"><span class="lineNum"> 511 </span> : : #define list_head_off(h, type, off) \</a> +<a name="512"><span class="lineNum"> 512 </span> : : ((type *)list_head_off((h), (off)))</a> +<a name="513"><span class="lineNum"> 513 </span> : : </a> +<a name="514"><span class="lineNum"> 514 </span> : : #define list_tail_off(h, type, off) \</a> +<a name="515"><span class="lineNum"> 515 </span> : : ((type *)list_tail_((h), (off)))</a> +<a name="516"><span class="lineNum"> 516 </span> : : </a> +<a name="517"><span class="lineNum"> 517 </span> : : #define list_add_off(h, n, off) \</a> +<a name="518"><span class="lineNum"> 518 </span> : : list_add((h), list_node_from_off_((n), (off)))</a> +<a name="519"><span class="lineNum"> 519 </span> : : </a> +<a name="520"><span class="lineNum"> 520 </span> : : #define list_del_off(n, off) \</a> +<a name="521"><span class="lineNum"> 521 </span> : : list_del(list_node_from_off_((n), (off)))</a> +<a name="522"><span class="lineNum"> 522 </span> : : </a> +<a name="523"><span class="lineNum"> 523 </span> : : #define list_del_from_off(h, n, off) \</a> +<a name="524"><span class="lineNum"> 524 </span> : : list_del_from(h, list_node_from_off_((n), (off)))</a> +<a name="525"><span class="lineNum"> 525 </span> : : </a> +<a name="526"><span class="lineNum"> 526 </span> : : /* Offset helper functions so we only single-evaluate. */</a> +<a name="527"><span class="lineNum"> 527 </span> :<span class="lineCov"> 376883 : static inline void *list_node_to_off_(struct list_node *node, size_t off)</span></a> +<a name="528"><span class="lineNum"> 528 </span> : : {</a> +<a name="529"><span class="lineNum"> 529 </span> :<span class="lineCov"> 376883 : return (void *)((char *)node - off);</span></a> +<a name="530"><span class="lineNum"> 530 </span> : : }</a> +<a name="531"><span class="lineNum"> 531 </span> :<span class="lineCov"> 603699 : static inline struct list_node *list_node_from_off_(void *ptr, size_t off)</span></a> +<a name="532"><span class="lineNum"> 532 </span> : : {</a> +<a name="533"><span class="lineNum"> 533 </span> :<span class="lineCov"> 603699 : return (struct list_node *)((char *)ptr + off);</span></a> +<a name="534"><span class="lineNum"> 534 </span> : : }</a> +<a name="535"><span class="lineNum"> 535 </span> : : </a> +<a name="536"><span class="lineNum"> 536 </span> : : /* Get the offset of the member, but make sure it's a list_node. */</a> +<a name="537"><span class="lineNum"> 537 </span> : : #define list_off_(type, member) \</a> +<a name="538"><span class="lineNum"> 538 </span> : : (container_off(type, member) + \</a> +<a name="539"><span class="lineNum"> 539 </span> : : check_type(((type *)0)->member, struct list_node))</a> +<a name="540"><span class="lineNum"> 540 </span> : : </a> +<a name="541"><span class="lineNum"> 541 </span> : : #define list_off_var_(var, member) \</a> +<a name="542"><span class="lineNum"> 542 </span> : : (container_off_var(var, member) + \</a> +<a name="543"><span class="lineNum"> 543 </span> : : check_type(var->member, struct list_node))</a> +<a name="544"><span class="lineNum"> 544 </span> : : </a> +<a name="545"><span class="lineNum"> 545 </span> : : </a> +<a name="546"><span class="lineNum"> 546 </span> : : #if HAVE_TYPEOF</a> +<a name="547"><span class="lineNum"> 547 </span> : : #define list_typeof(var) typeof(var)</a> +<a name="548"><span class="lineNum"> 548 </span> : : #else</a> +<a name="549"><span class="lineNum"> 549 </span> : : #define list_typeof(var) void *</a> +<a name="550"><span class="lineNum"> 550 </span> : : #endif</a> +<a name="551"><span class="lineNum"> 551 </span> : : </a> +<a name="552"><span class="lineNum"> 552 </span> : : </a> +<a name="553"><span class="lineNum"> 553 </span> : : /* Returns member, or NULL if at end of list. */</a> +<a name="554"><span class="lineNum"> 554 </span> :<span class="lineCov"> 3 : static inline void *list_entry_or_null(const struct list_head *h,</span></a> +<a name="555"><span class="lineNum"> 555 </span> : : const struct list_node *n,</a> +<a name="556"><span class="lineNum"> 556 </span> : : size_t off)</a> +<a name="557"><span class="lineNum"> 557 </span> : : {</a> +<a name="558"><span class="lineNum"> 558 </span> :<span class="lineCov"> 3 : if (n == &h->n)</span></a> +<a name="559"><span class="lineNum"> 559 </span> :<span class="lineCov"> 1 : return NULL;</span></a> +<a name="560"><span class="lineNum"> 560 </span> :<span class="lineCov"> 2 : return (char *)n - off;</span></a> +<a name="561"><span class="lineNum"> 561 </span> : : }</a> +<a name="562"><span class="lineNum"> 562 </span> : : </a> +<a name="563"><span class="lineNum"> 563 </span> : : /**</a> +<a name="564"><span class="lineNum"> 564 </span> : : * list_next - get the next entry in a list</a> +<a name="565"><span class="lineNum"> 565 </span> : : * @h: the list_head</a> +<a name="566"><span class="lineNum"> 566 </span> : : * @i: a pointer to an entry in the list.</a> +<a name="567"><span class="lineNum"> 567 </span> : : * @member: the list_node member of the structure</a> +<a name="568"><span class="lineNum"> 568 </span> : : *</a> +<a name="569"><span class="lineNum"> 569 </span> : : * If @i was the last entry in the list, returns NULL.</a> +<a name="570"><span class="lineNum"> 570 </span> : : *</a> +<a name="571"><span class="lineNum"> 571 </span> : : * Example:</a> +<a name="572"><span class="lineNum"> 572 </span> : : * struct child *second;</a> +<a name="573"><span class="lineNum"> 573 </span> : : * second = list_next(&parent->children, first, list);</a> +<a name="574"><span class="lineNum"> 574 </span> : : * if (!second)</a> +<a name="575"><span class="lineNum"> 575 </span> : : * printf("No second child!\n");</a> +<a name="576"><span class="lineNum"> 576 </span> : : */</a> +<a name="577"><span class="lineNum"> 577 </span> : : #define list_next(h, i, member) \</a> +<a name="578"><span class="lineNum"> 578 </span> : : ((list_typeof(i))list_entry_or_null(list_debug(h), \</a> +<a name="579"><span class="lineNum"> 579 </span> : : (i)->member.next, \</a> +<a name="580"><span class="lineNum"> 580 </span> : : list_off_var_((i), member)))</a> +<a name="581"><span class="lineNum"> 581 </span> : : </a> +<a name="582"><span class="lineNum"> 582 </span> : : </a> +<a name="583"><span class="lineNum"> 583 </span> : : #endif /* CCAN_LIST_H */</a> +</pre> + </td> + </tr> + </table> + <br> + + <table width="100%" border=0 cellspacing=0 cellpadding=0> + <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr> + <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.14</a></td></tr> + </table> + <br> + +</body> +</html> |