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