1 | /* chain.h |
---|
2 | * |
---|
3 | * This include file contains all the constants and structures associated |
---|
4 | * with the Doubly Linked Chain Handler. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * All rights assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
11 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
12 | * notice must appear in all copies of this file and its derivatives. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef __RTEMS_CHAIN_h |
---|
18 | #define __RTEMS_CHAIN_h |
---|
19 | |
---|
20 | #ifdef __cplusplus |
---|
21 | extern "C" { |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <rtems/score/address.h> |
---|
25 | |
---|
26 | /* |
---|
27 | * This is used to manage each element (node) which is placed |
---|
28 | * on a chain. |
---|
29 | * |
---|
30 | * NOTE: Typically, a more complicated structure will use the |
---|
31 | * chain package. The more complicated structure will |
---|
32 | * include a chain node as the first element in its |
---|
33 | * control structure. It will then call the chain package |
---|
34 | * with a pointer to that node element. The node pointer |
---|
35 | * and the higher level structure start at the same address |
---|
36 | * so the user can cast the pointers back and forth. |
---|
37 | * |
---|
38 | */ |
---|
39 | |
---|
40 | typedef struct Chain_Node_struct Chain_Node; |
---|
41 | |
---|
42 | struct Chain_Node_struct { |
---|
43 | Chain_Node *next; |
---|
44 | Chain_Node *previous; |
---|
45 | }; |
---|
46 | |
---|
47 | /* |
---|
48 | * This is used to manage a chain. A chain consists of a doubly |
---|
49 | * linked list of zero or more nodes. |
---|
50 | * |
---|
51 | * NOTE: This implementation does not require special checks for |
---|
52 | * manipulating the first and last elements on the chain. |
---|
53 | * To accomplish this the chain control structure is |
---|
54 | * treated as two overlapping chain nodes. The permanent |
---|
55 | * head of the chain overlays a node structure on the |
---|
56 | * first and permanent_null fields. The permanent tail |
---|
57 | * of the chain overlays a node structure on the |
---|
58 | * permanent_null and last elements of the structure. |
---|
59 | * |
---|
60 | */ |
---|
61 | |
---|
62 | typedef struct { |
---|
63 | Chain_Node *first; |
---|
64 | Chain_Node *permanent_null; |
---|
65 | Chain_Node *last; |
---|
66 | } Chain_Control; |
---|
67 | |
---|
68 | /* |
---|
69 | * _Chain_Initialize |
---|
70 | * |
---|
71 | * DESCRIPTION: |
---|
72 | * |
---|
73 | * This routine initializes the_chain structure to manage the |
---|
74 | * contiguous array of number_nodes nodes which starts at |
---|
75 | * starting_address. Each node is of node_size bytes. |
---|
76 | * |
---|
77 | */ |
---|
78 | |
---|
79 | void _Chain_Initialize( |
---|
80 | Chain_Control *the_chain, |
---|
81 | void *starting_address, |
---|
82 | unsigned32 number_nodes, |
---|
83 | unsigned32 node_size |
---|
84 | ); |
---|
85 | |
---|
86 | /* |
---|
87 | * _Chain_Initialize_empty |
---|
88 | * |
---|
89 | * DESCRIPTION: |
---|
90 | * |
---|
91 | * This routine initializes the specified chain to contain zero nodes. |
---|
92 | * |
---|
93 | */ |
---|
94 | |
---|
95 | STATIC INLINE void _Chain_Initialize_empty( |
---|
96 | Chain_Control *the_chain |
---|
97 | ); |
---|
98 | |
---|
99 | /* |
---|
100 | * _Chain_Are_nodes_equal |
---|
101 | * |
---|
102 | * DESCRIPTION: |
---|
103 | * |
---|
104 | * This function returns TRUE if LEFT and RIGHT are equal, |
---|
105 | * and FALSE otherwise. |
---|
106 | * |
---|
107 | */ |
---|
108 | |
---|
109 | STATIC INLINE boolean _Chain_Are_nodes_equal( |
---|
110 | Chain_Node *left, |
---|
111 | Chain_Node *right |
---|
112 | ); |
---|
113 | |
---|
114 | /* |
---|
115 | * _Chain_Extract_unprotected |
---|
116 | * |
---|
117 | * DESCRIPTION: |
---|
118 | * |
---|
119 | * This routine extracts the_node from the chain on which it resides. |
---|
120 | * It does NOT disable interrupts to insure the atomicity of the |
---|
121 | * extract operation. |
---|
122 | * |
---|
123 | */ |
---|
124 | |
---|
125 | STATIC INLINE void _Chain_Extract_unprotected( |
---|
126 | Chain_Node *the_node |
---|
127 | ); |
---|
128 | |
---|
129 | /* |
---|
130 | * _Chain_Extract |
---|
131 | * |
---|
132 | * DESCRIPTION: |
---|
133 | * |
---|
134 | * This routine extracts the_node from the chain on which it resides. |
---|
135 | * It disables interrupts to insure the atomicity of the |
---|
136 | * extract operation. |
---|
137 | * |
---|
138 | */ |
---|
139 | |
---|
140 | void _Chain_Extract( |
---|
141 | Chain_Node *the_node |
---|
142 | ); |
---|
143 | |
---|
144 | /* |
---|
145 | * _Chain_Get_unprotected |
---|
146 | * |
---|
147 | * DESCRIPTION: |
---|
148 | * |
---|
149 | * This function removes the first node from the_chain and returns |
---|
150 | * a pointer to that node. If the_chain is empty, then NULL is returned. |
---|
151 | * It does NOT disable interrupts to insure the atomicity of the |
---|
152 | * get operation. |
---|
153 | * |
---|
154 | */ |
---|
155 | |
---|
156 | STATIC INLINE Chain_Node *_Chain_Get_unprotected( |
---|
157 | Chain_Control *the_chain |
---|
158 | ); |
---|
159 | |
---|
160 | /* |
---|
161 | * _Chain_Get |
---|
162 | * |
---|
163 | * DESCRIPTION: |
---|
164 | * |
---|
165 | * This function removes the first node from the_chain and returns |
---|
166 | * a pointer to that node. If the_chain is empty, then NULL is returned. |
---|
167 | * It disables interrupts to insure the atomicity of the |
---|
168 | * get operation. |
---|
169 | * |
---|
170 | */ |
---|
171 | |
---|
172 | Chain_Node *_Chain_Get( |
---|
173 | Chain_Control *the_chain |
---|
174 | ); |
---|
175 | |
---|
176 | /* |
---|
177 | * _Chain_Get_first_unprotected |
---|
178 | * |
---|
179 | * DESCRIPTION: |
---|
180 | * |
---|
181 | * This function removes the first node from the_chain and returns |
---|
182 | * a pointer to that node. It does NOT disable interrupts to insure |
---|
183 | * the atomicity of the get operation. |
---|
184 | * |
---|
185 | */ |
---|
186 | |
---|
187 | STATIC INLINE Chain_Node *_Chain_Get_first_unprotected( |
---|
188 | Chain_Control *the_chain |
---|
189 | ); |
---|
190 | |
---|
191 | /* |
---|
192 | * _Chain_Insert_unprotected |
---|
193 | * |
---|
194 | * DESCRIPTION: |
---|
195 | * |
---|
196 | * This routine inserts the_node on a chain immediately following |
---|
197 | * after_node. It does NOT disable interrupts to insure the atomicity |
---|
198 | * of the extract operation. |
---|
199 | * |
---|
200 | */ |
---|
201 | |
---|
202 | STATIC INLINE void _Chain_Insert_unprotected( |
---|
203 | Chain_Node *after_node, |
---|
204 | Chain_Node *the_node |
---|
205 | ); |
---|
206 | |
---|
207 | /* |
---|
208 | * _Chain_Insert |
---|
209 | * |
---|
210 | * DESCRIPTION: |
---|
211 | * |
---|
212 | * This routine inserts the_node on a chain immediately following |
---|
213 | * after_node. It disables interrupts to insure the atomicity |
---|
214 | * of the extract operation. |
---|
215 | * |
---|
216 | */ |
---|
217 | |
---|
218 | void _Chain_Insert( |
---|
219 | Chain_Node *after_node, |
---|
220 | Chain_Node *the_node |
---|
221 | ); |
---|
222 | |
---|
223 | /* |
---|
224 | * _Chain_Append_unprotected |
---|
225 | * |
---|
226 | * DESCRIPTION: |
---|
227 | * |
---|
228 | * This routine appends the_node onto the end of the_chain. |
---|
229 | * It does NOT disable interrupts to insure the atomicity of the |
---|
230 | * append operation. |
---|
231 | * |
---|
232 | */ |
---|
233 | |
---|
234 | STATIC INLINE void _Chain_Append_unprotected( |
---|
235 | Chain_Control *the_chain, |
---|
236 | Chain_Node *the_node |
---|
237 | ); |
---|
238 | |
---|
239 | /* |
---|
240 | * _Chain_Append |
---|
241 | * |
---|
242 | * DESCRIPTION: |
---|
243 | * |
---|
244 | * This routine appends the_node onto the end of the_chain. |
---|
245 | * It disables interrupts to insure the atomicity of the |
---|
246 | * append operation. |
---|
247 | * |
---|
248 | */ |
---|
249 | |
---|
250 | void _Chain_Append( |
---|
251 | Chain_Control *the_chain, |
---|
252 | Chain_Node *the_node |
---|
253 | ); |
---|
254 | |
---|
255 | /* |
---|
256 | * _Chain_Prepend_unprotected |
---|
257 | * |
---|
258 | * DESCRIPTION: |
---|
259 | * |
---|
260 | * This routine prepends the_node onto the front of the_chain. |
---|
261 | * It does NOT disable interrupts to insure the atomicity of the |
---|
262 | * prepend operation. |
---|
263 | * |
---|
264 | */ |
---|
265 | |
---|
266 | STATIC INLINE void _Chain_Prepend_unprotected( |
---|
267 | Chain_Control *the_chain, |
---|
268 | Chain_Node *the_node |
---|
269 | ); |
---|
270 | |
---|
271 | /* |
---|
272 | * _Chain_Prepend |
---|
273 | * |
---|
274 | * DESCRIPTION: |
---|
275 | * |
---|
276 | * This routine prepends the_node onto the front of the_chain. |
---|
277 | * It disables interrupts to insure the atomicity of the |
---|
278 | * prepend operation. |
---|
279 | * |
---|
280 | */ |
---|
281 | |
---|
282 | STATIC INLINE void _Chain_Prepend( |
---|
283 | Chain_Control *the_chain, |
---|
284 | Chain_Node *the_node |
---|
285 | ); |
---|
286 | |
---|
287 | /* |
---|
288 | * _Chain_Head |
---|
289 | * |
---|
290 | * DESCRIPTION: |
---|
291 | * |
---|
292 | * This function returns a pointer to the first node on the chain. |
---|
293 | * |
---|
294 | */ |
---|
295 | |
---|
296 | STATIC INLINE Chain_Node *_Chain_Head( |
---|
297 | Chain_Control *the_chain |
---|
298 | ); |
---|
299 | |
---|
300 | /* |
---|
301 | * _Chain_Tail |
---|
302 | * |
---|
303 | * DESCRIPTION: |
---|
304 | * |
---|
305 | * This function returns a pointer to the last node on the chain. |
---|
306 | * |
---|
307 | */ |
---|
308 | |
---|
309 | STATIC INLINE Chain_Node *_Chain_Tail( |
---|
310 | Chain_Control *the_chain |
---|
311 | ); |
---|
312 | |
---|
313 | /* |
---|
314 | * _Chain_Is_head |
---|
315 | * |
---|
316 | * DESCRIPTION: |
---|
317 | * |
---|
318 | * This function returns TRUE if the_node is the head of the_chain and |
---|
319 | * FALSE otherwise. |
---|
320 | * |
---|
321 | */ |
---|
322 | |
---|
323 | STATIC INLINE boolean _Chain_Is_head( |
---|
324 | Chain_Control *the_chain, |
---|
325 | Chain_Node *the_node |
---|
326 | ); |
---|
327 | |
---|
328 | /* |
---|
329 | * _Chain_Is_tail |
---|
330 | * |
---|
331 | * DESCRIPTION: |
---|
332 | * |
---|
333 | * This function returns TRUE if the_node is the tail of the_chain and |
---|
334 | * FALSE otherwise. |
---|
335 | * |
---|
336 | */ |
---|
337 | |
---|
338 | STATIC INLINE boolean _Chain_Is_tail( |
---|
339 | Chain_Control *the_chain, |
---|
340 | Chain_Node *the_node |
---|
341 | ); |
---|
342 | |
---|
343 | /* |
---|
344 | * _Chain_Is_first |
---|
345 | * |
---|
346 | * DESCRIPTION: |
---|
347 | * |
---|
348 | * This function returns TRUE if the_node is the first node on a chain and |
---|
349 | * FALSE otherwise. |
---|
350 | * |
---|
351 | */ |
---|
352 | |
---|
353 | STATIC INLINE boolean _Chain_Is_first( |
---|
354 | Chain_Node *the_node |
---|
355 | ); |
---|
356 | |
---|
357 | /* |
---|
358 | * _Chain_Is_last |
---|
359 | * |
---|
360 | * DESCRIPTION: |
---|
361 | * |
---|
362 | * This function returns TRUE if the_node is the last node on a chain and |
---|
363 | * FALSE otherwise. |
---|
364 | * |
---|
365 | */ |
---|
366 | |
---|
367 | STATIC INLINE boolean _Chain_Is_last( |
---|
368 | Chain_Node *the_node |
---|
369 | ); |
---|
370 | |
---|
371 | /* |
---|
372 | * _Chain_Is_empty |
---|
373 | * |
---|
374 | * DESCRIPTION: |
---|
375 | * |
---|
376 | * This function returns TRUE if there a no nodes on the_chain and |
---|
377 | * FALSE otherwise. |
---|
378 | * |
---|
379 | */ |
---|
380 | |
---|
381 | STATIC INLINE boolean _Chain_Is_empty( |
---|
382 | Chain_Control *the_chain |
---|
383 | ); |
---|
384 | |
---|
385 | /* |
---|
386 | * _Chain_Has_only_one_node |
---|
387 | * |
---|
388 | * DESCRIPTION: |
---|
389 | * |
---|
390 | * This function returns TRUE if there is only one node on the_chain and |
---|
391 | * FALSE otherwise. |
---|
392 | * |
---|
393 | */ |
---|
394 | |
---|
395 | STATIC INLINE boolean _Chain_Has_only_one_node( |
---|
396 | Chain_Control *the_chain |
---|
397 | ); |
---|
398 | |
---|
399 | /* |
---|
400 | * _Chain_Is_null |
---|
401 | * |
---|
402 | * DESCRIPTION: |
---|
403 | * |
---|
404 | * This function returns TRUE if the_chain is NULL and FALSE otherwise. |
---|
405 | * |
---|
406 | */ |
---|
407 | |
---|
408 | STATIC INLINE boolean _Chain_Is_null( |
---|
409 | Chain_Control *the_chain |
---|
410 | ); |
---|
411 | |
---|
412 | /* |
---|
413 | * _Chain_Is_null_node |
---|
414 | * |
---|
415 | * DESCRIPTION: |
---|
416 | * |
---|
417 | * This function returns TRUE if the_node is NULL and FALSE otherwise. |
---|
418 | * |
---|
419 | */ |
---|
420 | |
---|
421 | STATIC INLINE boolean _Chain_Is_null_node( |
---|
422 | Chain_Node *the_node |
---|
423 | ); |
---|
424 | |
---|
425 | #include <rtems/score/chain.inl> |
---|
426 | |
---|
427 | #ifdef __cplusplus |
---|
428 | } |
---|
429 | #endif |
---|
430 | |
---|
431 | #endif |
---|
432 | /* end of include file */ |
---|