[72d2ec4d] | 1 | /** |
---|
| 2 | * @file rtems/chain.inl |
---|
| 3 | * |
---|
| 4 | * This include file contains all the constants and structures associated |
---|
| 5 | * with the Chain API in RTEMS. The chain is a double linked list that |
---|
| 6 | * is part of the Super Core. This is the published interface to that |
---|
| 7 | * code. |
---|
| 8 | * |
---|
| 9 | * Iterate the node of a chain can be performed with the following code: |
---|
| 10 | * |
---|
| 11 | * rtems_chain_control* cc = &object->pending; |
---|
| 12 | * rtems_chain_node* cn = cc->first; |
---|
| 13 | * while (!rtems_chain_is_tail (cc, cn)) |
---|
| 14 | * { |
---|
| 15 | * cn = cn->next; |
---|
| 16 | * } |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | /* |
---|
| 20 | * COPYRIGHT (c) 1989-2008. |
---|
| 21 | * On-Line Applications Research Corporation (OAR). |
---|
| 22 | * |
---|
| 23 | * The license and distribution terms for this file may be |
---|
| 24 | * found in the file LICENSE in this distribution or at |
---|
| 25 | * http://www.rtems.com/license/LICENSE. |
---|
| 26 | * |
---|
| 27 | * $Id$ |
---|
| 28 | */ |
---|
| 29 | |
---|
[ef49476] | 30 | #ifndef _RTEMS_CHAIN_H |
---|
| 31 | # error "Never use <rtems/chain.inl> directly; include <rtems/chain.h> instead." |
---|
| 32 | #endif |
---|
| 33 | |
---|
[72d2ec4d] | 34 | #ifndef _RTEMS_CHAIN_INL |
---|
| 35 | #define _RTEMS_CHAIN_INL |
---|
| 36 | |
---|
| 37 | #include <rtems/score/chain.inl> |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * @brief Initialize this Chain as Empty |
---|
| 41 | * |
---|
| 42 | * This routine initializes the specified chain to contain zero nodes. |
---|
| 43 | * |
---|
| 44 | * @param[in] the_chain is the chain to be initialized. |
---|
| 45 | */ |
---|
| 46 | RTEMS_INLINE_ROUTINE void rtems_chain_initialize_empty( |
---|
| 47 | rtems_chain_control *the_chain |
---|
| 48 | ) |
---|
| 49 | { |
---|
| 50 | _Chain_Initialize_empty( the_chain ); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * @brief Is the Chain Node Pointer NULL |
---|
| 55 | * |
---|
[484a769] | 56 | * This function returns true if the_node is NULL and false otherwise. |
---|
[72d2ec4d] | 57 | * |
---|
| 58 | * @param[in] the_node is the node pointer to check. |
---|
| 59 | * |
---|
[484a769] | 60 | * @return This method returns true if the_node is NULL and false otherwise. |
---|
[72d2ec4d] | 61 | */ |
---|
[484a769] | 62 | RTEMS_INLINE_ROUTINE bool rtems_chain_is_null_node( |
---|
[72d2ec4d] | 63 | const rtems_chain_node *the_node |
---|
| 64 | ) |
---|
| 65 | { |
---|
| 66 | return _Chain_Is_null_node( the_node ); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * @brief Return pointer to Chain Head |
---|
| 71 | * |
---|
| 72 | * This function returns a pointer to the first node on the chain. |
---|
| 73 | * |
---|
| 74 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 75 | * |
---|
| 76 | * @return This method returns the permanent head node of the chain. |
---|
| 77 | */ |
---|
| 78 | RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_head( |
---|
| 79 | rtems_chain_control *the_chain |
---|
| 80 | ) |
---|
| 81 | { |
---|
| 82 | return _Chain_Head( the_chain ); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * @brief Return pointer to Chain Tail |
---|
| 87 | * |
---|
| 88 | * This function returns a pointer to the last node on the chain. |
---|
| 89 | * |
---|
| 90 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 91 | * |
---|
| 92 | * @return This method returns the permanent tail node of the chain. |
---|
| 93 | */ |
---|
| 94 | RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_tail( |
---|
| 95 | rtems_chain_control *the_chain |
---|
| 96 | ) |
---|
| 97 | { |
---|
| 98 | return _Chain_Tail( the_chain ); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * @brief Are Two Nodes Equal |
---|
| 103 | * |
---|
[484a769] | 104 | * This function returns true if @a left and @a right are equal, |
---|
| 105 | * and false otherwise. |
---|
[72d2ec4d] | 106 | * |
---|
| 107 | * @param[in] left is the node on the left hand side of the comparison. |
---|
| 108 | * @param[in] right is the node on the left hand side of the comparison. |
---|
| 109 | * |
---|
[484a769] | 110 | * @return This function returns true if @a left and @a right are equal, |
---|
| 111 | * and false otherwise. |
---|
[72d2ec4d] | 112 | */ |
---|
[484a769] | 113 | RTEMS_INLINE_ROUTINE bool rtems_chain_are_nodes_equal( |
---|
[72d2ec4d] | 114 | const rtems_chain_node *left, |
---|
| 115 | const rtems_chain_node *right |
---|
| 116 | ) |
---|
| 117 | { |
---|
| 118 | return _Chain_Are_nodes_equal( left, right ); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * @brief Is the Chain Empty |
---|
| 123 | * |
---|
[484a769] | 124 | * This function returns true if there a no nodes on @a the_chain and |
---|
| 125 | * false otherwise. |
---|
[72d2ec4d] | 126 | * |
---|
| 127 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 128 | * |
---|
[484a769] | 129 | * @return This function returns true if there a no nodes on @a the_chain and |
---|
| 130 | * false otherwise. |
---|
[72d2ec4d] | 131 | */ |
---|
[484a769] | 132 | RTEMS_INLINE_ROUTINE bool rtems_chain_is_empty( |
---|
[72d2ec4d] | 133 | rtems_chain_control *the_chain |
---|
| 134 | ) |
---|
| 135 | { |
---|
| 136 | return _Chain_Is_empty( the_chain ); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * @brief Is this the First Node on the Chain |
---|
| 141 | * |
---|
[484a769] | 142 | * This function returns true if the_node is the first node on a chain and |
---|
| 143 | * false otherwise. |
---|
[72d2ec4d] | 144 | * |
---|
| 145 | * @param[in] the_node is the node the caller wants to know if it is |
---|
| 146 | * the first node on a chain. |
---|
| 147 | * |
---|
[484a769] | 148 | * @return This function returns true if @a the_node is the first node on |
---|
| 149 | * a chain and false otherwise. |
---|
[72d2ec4d] | 150 | */ |
---|
[484a769] | 151 | RTEMS_INLINE_ROUTINE bool rtems_chain_is_first( |
---|
[72d2ec4d] | 152 | const rtems_chain_node *the_node |
---|
| 153 | ) |
---|
| 154 | { |
---|
| 155 | return _Chain_Is_first( the_node ); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | * @brief Is this the Last Node on the Chain |
---|
| 160 | * |
---|
[484a769] | 161 | * This function returns true if @a the_node is the last node on a chain and |
---|
| 162 | * false otherwise. |
---|
[72d2ec4d] | 163 | * |
---|
| 164 | * @param[in] the_node is the node to check as the last node. |
---|
| 165 | * |
---|
[484a769] | 166 | * @return This function returns true if @a the_node is the last node on |
---|
| 167 | * a chain and false otherwise. |
---|
[72d2ec4d] | 168 | */ |
---|
[484a769] | 169 | RTEMS_INLINE_ROUTINE bool rtems_chain_is_last( |
---|
[72d2ec4d] | 170 | const rtems_chain_node *the_node |
---|
| 171 | ) |
---|
| 172 | { |
---|
| 173 | return _Chain_Is_last( the_node ); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * @brief Does this Chain have only One Node |
---|
| 178 | * |
---|
[484a769] | 179 | * This function returns true if there is only one node on @a the_chain and |
---|
| 180 | * false otherwise. |
---|
[72d2ec4d] | 181 | * |
---|
| 182 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 183 | * |
---|
[484a769] | 184 | * @return This function returns true if there is only one node on |
---|
| 185 | * @a the_chain and false otherwise. |
---|
[72d2ec4d] | 186 | */ |
---|
[484a769] | 187 | RTEMS_INLINE_ROUTINE bool rtems_chain_has_only_one_node( |
---|
[72d2ec4d] | 188 | const rtems_chain_control *the_chain |
---|
| 189 | ) |
---|
| 190 | { |
---|
| 191 | return _Chain_Has_only_one_node( the_chain ); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /** |
---|
| 195 | * @brief Is this Node the Chain Head |
---|
| 196 | * |
---|
[484a769] | 197 | * This function returns true if @a the_node is the head of the_chain and |
---|
| 198 | * false otherwise. |
---|
[72d2ec4d] | 199 | * |
---|
| 200 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 201 | * @param[in] the_node is the node to check for being the Chain Head. |
---|
| 202 | * |
---|
[484a769] | 203 | * @return This function returns true if @a the_node is the head of |
---|
| 204 | * @a the_chain and false otherwise. |
---|
[72d2ec4d] | 205 | */ |
---|
[484a769] | 206 | RTEMS_INLINE_ROUTINE bool rtems_chain_is_head( |
---|
[72d2ec4d] | 207 | rtems_chain_control *the_chain, |
---|
| 208 | const rtems_chain_node *the_node |
---|
| 209 | ) |
---|
| 210 | { |
---|
| 211 | return _Chain_Is_head( the_chain, the_node ); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | /** |
---|
| 215 | * @brief Is this Node the Chail Tail |
---|
| 216 | * |
---|
[484a769] | 217 | * This function returns true if the_node is the tail of the_chain and |
---|
| 218 | * false otherwise. |
---|
[72d2ec4d] | 219 | * |
---|
| 220 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 221 | * @param[in] the_node is the node to check for being the Chain Tail. |
---|
| 222 | */ |
---|
[484a769] | 223 | RTEMS_INLINE_ROUTINE bool rtems_chain_is_tail( |
---|
[72d2ec4d] | 224 | rtems_chain_control *the_chain, |
---|
| 225 | const rtems_chain_node *the_node |
---|
| 226 | ) |
---|
| 227 | { |
---|
| 228 | return _Chain_Is_tail( the_chain, the_node ); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | /** |
---|
| 232 | * @brief Extract the specified node from a chain |
---|
| 233 | * |
---|
| 234 | * This routine extracts @a the_node from the chain on which it resides. |
---|
| 235 | * It disables interrupts to ensure the atomicity of the |
---|
| 236 | * extract operation. |
---|
| 237 | * |
---|
| 238 | * @arg the_node specifies the node to extract |
---|
| 239 | */ |
---|
| 240 | RTEMS_INLINE_ROUTINE void rtems_chain_extract( |
---|
| 241 | rtems_chain_node *the_node |
---|
| 242 | ) |
---|
| 243 | { |
---|
| 244 | _Chain_Extract( the_node ); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | /** |
---|
| 248 | * @brief Obtain the first node on a chain |
---|
| 249 | * |
---|
| 250 | * This function removes the first node from @a the_chain and returns |
---|
| 251 | * a pointer to that node. If @a the_chain is empty, then NULL is returned. |
---|
| 252 | * |
---|
| 253 | * @return This method returns a pointer a node. If a node was removed, |
---|
| 254 | * then a pointer to that node is returned. If @a the_chain was |
---|
| 255 | * empty, then NULL is returned. |
---|
| 256 | * |
---|
| 257 | * @note It disables interrupts to ensure the atomicity of the get operation. |
---|
| 258 | */ |
---|
| 259 | RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_get( |
---|
| 260 | rtems_chain_control *the_chain |
---|
| 261 | ) |
---|
| 262 | { |
---|
| 263 | return _Chain_Get( the_chain ); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | /** |
---|
| 267 | * @brief Insert a node on a chain |
---|
| 268 | * |
---|
| 269 | * This routine inserts @a the_node on a chain immediately following |
---|
| 270 | * @a after_node. |
---|
| 271 | * |
---|
| 272 | * @note It disables interrupts to ensure the atomicity |
---|
| 273 | * of the extract operation. |
---|
| 274 | */ |
---|
| 275 | RTEMS_INLINE_ROUTINE void rtems_chain_insert( |
---|
| 276 | rtems_chain_node *after_node, |
---|
| 277 | rtems_chain_node *the_node |
---|
| 278 | ) |
---|
| 279 | { |
---|
| 280 | _Chain_Insert( after_node, the_node ); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | /** |
---|
| 284 | * @brief Append a node on the end of a chain |
---|
| 285 | * |
---|
| 286 | * This routine appends @a the_node onto the end of @a the_chain. |
---|
| 287 | * |
---|
| 288 | * @note It disables interrupts to ensure the atomicity of the |
---|
| 289 | * append operation. |
---|
| 290 | */ |
---|
| 291 | RTEMS_INLINE_ROUTINE void rtems_chain_append( |
---|
| 292 | rtems_chain_control *the_chain, |
---|
| 293 | rtems_chain_node *the_node |
---|
| 294 | ) |
---|
| 295 | { |
---|
| 296 | _Chain_Append( the_chain, the_node ); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | /** @brief Prepend a Node |
---|
| 300 | * |
---|
| 301 | * This routine prepends the_node onto the front of the_chain. |
---|
| 302 | * |
---|
| 303 | * @param[in] the_chain is the chain to be operated upon. |
---|
| 304 | * @param[in] the_node is the node to be prepended. |
---|
| 305 | * |
---|
| 306 | * @note It disables interrupts to ensure the atomicity of the |
---|
| 307 | * prepend operation. |
---|
| 308 | */ |
---|
| 309 | RTEMS_INLINE_ROUTINE void rtems_chain_prepend( |
---|
| 310 | rtems_chain_control *the_chain, |
---|
| 311 | rtems_chain_node *the_node |
---|
| 312 | ) |
---|
| 313 | { |
---|
| 314 | _Chain_Prepend( the_chain, the_node ); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | #endif |
---|
| 318 | /* end of include file */ |
---|