1 | /** |
---|
2 | * @file rtems/score/chain.inl |
---|
3 | * |
---|
4 | * This include file contains the bodies of the routines which are |
---|
5 | * associated with doubly linked chains and inlined. |
---|
6 | * |
---|
7 | * @note The routines in this file are ordered from simple |
---|
8 | * to complex. No other Chain Handler routine is referenced |
---|
9 | * unless it has already been defined. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-2006. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.com/license/LICENSE. |
---|
19 | * |
---|
20 | * $Id$ |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_CHAIN_H |
---|
24 | # error "Never use <rtems/score/chain.inl> directly; include <rtems/score/chain.h> instead." |
---|
25 | #endif |
---|
26 | |
---|
27 | #ifndef _RTEMS_SCORE_CHAIN_INL |
---|
28 | #define _RTEMS_SCORE_CHAIN_INL |
---|
29 | |
---|
30 | /** |
---|
31 | * @addtogroup ScoreChain |
---|
32 | * @{ |
---|
33 | */ |
---|
34 | |
---|
35 | /** @brief Are Two Nodes Equal |
---|
36 | * |
---|
37 | * This function returns TRUE if @a left and @a right are equal, |
---|
38 | * and FALSE otherwise. |
---|
39 | * |
---|
40 | * @param[in] left is the node on the left hand side of the comparison. |
---|
41 | * @param[in] right is the node on the left hand side of the comparison. |
---|
42 | * |
---|
43 | * @return This function returns TRUE if @a left and @a right are equal, |
---|
44 | * and FALSE otherwise. |
---|
45 | */ |
---|
46 | RTEMS_INLINE_ROUTINE bool _Chain_Are_nodes_equal( |
---|
47 | const Chain_Node *left, |
---|
48 | const Chain_Node *right |
---|
49 | ) |
---|
50 | { |
---|
51 | return left == right; |
---|
52 | } |
---|
53 | |
---|
54 | /** @brief Is this Chain Control Pointer Null |
---|
55 | * |
---|
56 | * This function returns TRUE if the_chain is NULL and FALSE otherwise. |
---|
57 | * |
---|
58 | * @param[in] the_chain is the chain to be checked for empty status. |
---|
59 | * |
---|
60 | * @return This method returns TRUE if the_chain is NULL and FALSE otherwise. |
---|
61 | */ |
---|
62 | RTEMS_INLINE_ROUTINE bool _Chain_Is_null( |
---|
63 | const Chain_Control *the_chain |
---|
64 | ) |
---|
65 | { |
---|
66 | return (the_chain == NULL); |
---|
67 | } |
---|
68 | |
---|
69 | /** @brief Is the Chain Node Pointer NULL |
---|
70 | * |
---|
71 | * This function returns TRUE if the_node is NULL and FALSE otherwise. |
---|
72 | * |
---|
73 | * @param[in] the_node is the node pointer to check. |
---|
74 | * |
---|
75 | * @return This method returns TRUE if the_node is NULL and FALSE otherwise. |
---|
76 | */ |
---|
77 | RTEMS_INLINE_ROUTINE bool _Chain_Is_null_node( |
---|
78 | const Chain_Node *the_node |
---|
79 | ) |
---|
80 | { |
---|
81 | return (the_node == NULL); |
---|
82 | } |
---|
83 | |
---|
84 | /** @brief Return pointer to Chain Head |
---|
85 | * |
---|
86 | * This function returns a pointer to the first node on the chain. |
---|
87 | * |
---|
88 | * @param[in] the_chain is the chain to be operated upon. |
---|
89 | * |
---|
90 | * @return This method returns the permanent head node of the chain. |
---|
91 | */ |
---|
92 | RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Head( |
---|
93 | Chain_Control *the_chain |
---|
94 | ) |
---|
95 | { |
---|
96 | return (Chain_Node *) the_chain; |
---|
97 | } |
---|
98 | |
---|
99 | /** @brief Return pointer to Chain Tail |
---|
100 | * |
---|
101 | * This function returns a pointer to the last node on the chain. |
---|
102 | * |
---|
103 | * @param[in] the_chain is the chain to be operated upon. |
---|
104 | * |
---|
105 | * @return This method returns the permanent tail node of the chain. |
---|
106 | */ |
---|
107 | RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Tail( |
---|
108 | Chain_Control *the_chain |
---|
109 | ) |
---|
110 | { |
---|
111 | return (Chain_Node *) &the_chain->permanent_null; |
---|
112 | } |
---|
113 | |
---|
114 | /** @brief Is the Chain Empty |
---|
115 | * |
---|
116 | * This function returns TRUE if there a no nodes on @a the_chain and |
---|
117 | * FALSE otherwise. |
---|
118 | * |
---|
119 | * @param[in] the_chain is the chain to be operated upon. |
---|
120 | * |
---|
121 | * @return This function returns TRUE if there a no nodes on @a the_chain and |
---|
122 | * FALSE otherwise. |
---|
123 | */ |
---|
124 | RTEMS_INLINE_ROUTINE bool _Chain_Is_empty( |
---|
125 | Chain_Control *the_chain |
---|
126 | ) |
---|
127 | { |
---|
128 | return (the_chain->first == _Chain_Tail(the_chain)); |
---|
129 | } |
---|
130 | |
---|
131 | /** @brief Is this the First Node on the Chain |
---|
132 | * |
---|
133 | * This function returns TRUE if the_node is the first node on a chain and |
---|
134 | * FALSE otherwise. |
---|
135 | * |
---|
136 | * @param[in] the_node is the node the caller wants to know if it is |
---|
137 | * the first node on a chain. |
---|
138 | * |
---|
139 | * @return This function returns TRUE if @a the_node is the first node on |
---|
140 | * a chain and FALSE otherwise. |
---|
141 | */ |
---|
142 | RTEMS_INLINE_ROUTINE bool _Chain_Is_first( |
---|
143 | const Chain_Node *the_node |
---|
144 | ) |
---|
145 | { |
---|
146 | return (the_node->previous == NULL); |
---|
147 | } |
---|
148 | |
---|
149 | /** @brief Is this the Last Node on the Chain |
---|
150 | * |
---|
151 | * This function returns TRUE if @a the_node is the last node on a chain and |
---|
152 | * FALSE otherwise. |
---|
153 | * |
---|
154 | * @param[in] the_node is the node to check as the last node. |
---|
155 | * |
---|
156 | * @return This function returns TRUE if @a the_node is the last node on |
---|
157 | * a chain and FALSE otherwise. |
---|
158 | */ |
---|
159 | RTEMS_INLINE_ROUTINE bool _Chain_Is_last( |
---|
160 | const Chain_Node *the_node |
---|
161 | ) |
---|
162 | { |
---|
163 | return (the_node->next == NULL); |
---|
164 | } |
---|
165 | |
---|
166 | /** @brief Does this Chain have only One Node |
---|
167 | * |
---|
168 | * This function returns TRUE if there is only one node on @a the_chain and |
---|
169 | * FALSE otherwise. |
---|
170 | * |
---|
171 | * @param[in] the_chain is the chain to be operated upon. |
---|
172 | * |
---|
173 | * @return This function returns TRUE if there is only one node on |
---|
174 | * @a the_chain and FALSE otherwise. |
---|
175 | */ |
---|
176 | RTEMS_INLINE_ROUTINE bool _Chain_Has_only_one_node( |
---|
177 | const Chain_Control *the_chain |
---|
178 | ) |
---|
179 | { |
---|
180 | return (the_chain->first == the_chain->last); |
---|
181 | } |
---|
182 | |
---|
183 | /** @brief Is this Node the Chain Head |
---|
184 | * |
---|
185 | * This function returns TRUE if @a the_node is the head of the_chain and |
---|
186 | * FALSE otherwise. |
---|
187 | * |
---|
188 | * @param[in] the_chain is the chain to be operated upon. |
---|
189 | * @param[in] the_node is the node to check for being the Chain Head. |
---|
190 | * |
---|
191 | * @return This function returns TRUE if @a the_node is the head of |
---|
192 | * @a the_chain and FALSE otherwise. |
---|
193 | */ |
---|
194 | RTEMS_INLINE_ROUTINE bool _Chain_Is_head( |
---|
195 | Chain_Control *the_chain, |
---|
196 | const Chain_Node *the_node |
---|
197 | ) |
---|
198 | { |
---|
199 | return (the_node == _Chain_Head(the_chain)); |
---|
200 | } |
---|
201 | |
---|
202 | /** @brief Is this Node the Chail Tail |
---|
203 | * |
---|
204 | * This function returns TRUE if the_node is the tail of the_chain and |
---|
205 | * FALSE otherwise. |
---|
206 | * |
---|
207 | * @param[in] the_chain is the chain to be operated upon. |
---|
208 | * @param[in] the_node is the node to check for being the Chain Tail. |
---|
209 | */ |
---|
210 | RTEMS_INLINE_ROUTINE bool _Chain_Is_tail( |
---|
211 | Chain_Control *the_chain, |
---|
212 | const Chain_Node *the_node |
---|
213 | ) |
---|
214 | { |
---|
215 | return (the_node == _Chain_Tail(the_chain)); |
---|
216 | } |
---|
217 | |
---|
218 | /** @brief Initialize this Chain as Empty |
---|
219 | * |
---|
220 | * This routine initializes the specified chain to contain zero nodes. |
---|
221 | * |
---|
222 | * @param[in] the_chain is the chain to be initialized. |
---|
223 | */ |
---|
224 | RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty( |
---|
225 | Chain_Control *the_chain |
---|
226 | ) |
---|
227 | { |
---|
228 | the_chain->first = _Chain_Tail(the_chain); |
---|
229 | the_chain->permanent_null = NULL; |
---|
230 | the_chain->last = _Chain_Head(the_chain); |
---|
231 | } |
---|
232 | |
---|
233 | /** @brief Extract this Node (unprotected) |
---|
234 | * |
---|
235 | * This routine extracts the_node from the chain on which it resides. |
---|
236 | * It does NOT disable interrupts to ensure the atomicity of the |
---|
237 | * extract operation. |
---|
238 | * |
---|
239 | * @param[in] the_node is the node to be extracted. |
---|
240 | */ |
---|
241 | RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected( |
---|
242 | Chain_Node *the_node |
---|
243 | ) |
---|
244 | { |
---|
245 | Chain_Node *next; |
---|
246 | Chain_Node *previous; |
---|
247 | |
---|
248 | next = the_node->next; |
---|
249 | previous = the_node->previous; |
---|
250 | next->previous = previous; |
---|
251 | previous->next = next; |
---|
252 | } |
---|
253 | |
---|
254 | /** @brief Get the First Node (unprotected) |
---|
255 | * |
---|
256 | * This function removes the first node from the_chain and returns |
---|
257 | * a pointer to that node. It does NOT disable interrupts to ensure |
---|
258 | * the atomicity of the get operation. |
---|
259 | * |
---|
260 | * @param[in] the_chain is the chain to attempt to get the first node from. |
---|
261 | * |
---|
262 | * @return This method returns the first node on the chain even if it is |
---|
263 | * the Chain Tail. |
---|
264 | * |
---|
265 | * @note This routine assumes that there is at least one node on the chain |
---|
266 | * and always returns a node even if it is the Chain Tail. |
---|
267 | */ |
---|
268 | RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Get_first_unprotected( |
---|
269 | Chain_Control *the_chain |
---|
270 | ) |
---|
271 | { |
---|
272 | Chain_Node *return_node; |
---|
273 | Chain_Node *new_first; |
---|
274 | |
---|
275 | return_node = the_chain->first; |
---|
276 | new_first = return_node->next; |
---|
277 | the_chain->first = new_first; |
---|
278 | new_first->previous = _Chain_Head(the_chain); |
---|
279 | |
---|
280 | return return_node; |
---|
281 | } |
---|
282 | |
---|
283 | /** @brief Get the First Node (unprotected) |
---|
284 | * |
---|
285 | * This function removes the first node from the_chain and returns |
---|
286 | * a pointer to that node. If the_chain is empty, then NULL is returned. |
---|
287 | * |
---|
288 | * @param[in] the_chain is the chain to attempt to get the first node from. |
---|
289 | * |
---|
290 | * @return This method returns the first node on the chain or NULL if the |
---|
291 | * chain is empty. |
---|
292 | * |
---|
293 | * @note It does NOT disable interrupts to ensure the atomicity of the |
---|
294 | * get operation. |
---|
295 | */ |
---|
296 | RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Get_unprotected( |
---|
297 | Chain_Control *the_chain |
---|
298 | ) |
---|
299 | { |
---|
300 | if ( !_Chain_Is_empty(the_chain)) |
---|
301 | return _Chain_Get_first_unprotected(the_chain); |
---|
302 | else |
---|
303 | return NULL; |
---|
304 | } |
---|
305 | |
---|
306 | /** @brief Insert a Node (unprotected) |
---|
307 | * |
---|
308 | * This routine inserts the_node on a chain immediately following |
---|
309 | * after_node. |
---|
310 | * |
---|
311 | * @param[in] after_node is the node which will precede @a the_node on the |
---|
312 | * chain. |
---|
313 | * @param[in] the_node is the node to be inserted. |
---|
314 | * |
---|
315 | * @note It does NOT disable interrupts to ensure the atomicity |
---|
316 | * of the extract operation. |
---|
317 | */ |
---|
318 | RTEMS_INLINE_ROUTINE void _Chain_Insert_unprotected( |
---|
319 | Chain_Node *after_node, |
---|
320 | Chain_Node *the_node |
---|
321 | ) |
---|
322 | { |
---|
323 | Chain_Node *before_node; |
---|
324 | |
---|
325 | the_node->previous = after_node; |
---|
326 | before_node = after_node->next; |
---|
327 | after_node->next = the_node; |
---|
328 | the_node->next = before_node; |
---|
329 | before_node->previous = the_node; |
---|
330 | } |
---|
331 | |
---|
332 | /** @brief Append a Node (unprotected) |
---|
333 | * |
---|
334 | * This routine appends the_node onto the end of the_chain. |
---|
335 | * |
---|
336 | * @param[in] the_chain is the chain to be operated upon. |
---|
337 | * @param[in] the_node is the node to be appended. |
---|
338 | * |
---|
339 | * @note It does NOT disable interrupts to ensure the atomicity of the |
---|
340 | * append operation. |
---|
341 | */ |
---|
342 | RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected( |
---|
343 | Chain_Control *the_chain, |
---|
344 | Chain_Node *the_node |
---|
345 | ) |
---|
346 | { |
---|
347 | Chain_Node *old_last_node; |
---|
348 | |
---|
349 | the_node->next = _Chain_Tail(the_chain); |
---|
350 | old_last_node = the_chain->last; |
---|
351 | the_chain->last = the_node; |
---|
352 | old_last_node->next = the_node; |
---|
353 | the_node->previous = old_last_node; |
---|
354 | } |
---|
355 | |
---|
356 | /** @brief Prepend a Node (unprotected) |
---|
357 | * |
---|
358 | * This routine prepends the_node onto the front of the_chain. |
---|
359 | * |
---|
360 | * @param[in] the_chain is the chain to be operated upon. |
---|
361 | * @param[in] the_node is the node to be prepended. |
---|
362 | * |
---|
363 | * @note It does NOT disable interrupts to ensure the atomicity of the |
---|
364 | * prepend operation. |
---|
365 | */ |
---|
366 | RTEMS_INLINE_ROUTINE void _Chain_Prepend_unprotected( |
---|
367 | Chain_Control *the_chain, |
---|
368 | Chain_Node *the_node |
---|
369 | ) |
---|
370 | { |
---|
371 | _Chain_Insert_unprotected(_Chain_Head(the_chain), the_node); |
---|
372 | } |
---|
373 | |
---|
374 | /** @brief Prepend a Node (protected) |
---|
375 | * |
---|
376 | * This routine prepends the_node onto the front of the_chain. |
---|
377 | * |
---|
378 | * @param[in] the_chain is the chain to be operated upon. |
---|
379 | * @param[in] the_node is the node to be prepended. |
---|
380 | * |
---|
381 | * @note It disables interrupts to ensure the atomicity of the |
---|
382 | * prepend operation. |
---|
383 | */ |
---|
384 | RTEMS_INLINE_ROUTINE void _Chain_Prepend( |
---|
385 | Chain_Control *the_chain, |
---|
386 | Chain_Node *the_node |
---|
387 | ) |
---|
388 | { |
---|
389 | _Chain_Insert(_Chain_Head(the_chain), the_node); |
---|
390 | } |
---|
391 | |
---|
392 | /**@}*/ |
---|
393 | |
---|
394 | #endif |
---|
395 | /* end of include file */ |
---|