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_Extract |
---|
88 | * |
---|
89 | * DESCRIPTION: |
---|
90 | * |
---|
91 | * This routine extracts the_node from the chain on which it resides. |
---|
92 | * It disables interrupts to insure the atomicity of the |
---|
93 | * extract operation. |
---|
94 | * |
---|
95 | */ |
---|
96 | |
---|
97 | void _Chain_Extract( |
---|
98 | Chain_Node *the_node |
---|
99 | ); |
---|
100 | |
---|
101 | /* |
---|
102 | * _Chain_Get |
---|
103 | * |
---|
104 | * DESCRIPTION: |
---|
105 | * |
---|
106 | * This function removes the first node from the_chain and returns |
---|
107 | * a pointer to that node. If the_chain is empty, then NULL is returned. |
---|
108 | * It disables interrupts to insure the atomicity of the |
---|
109 | * get operation. |
---|
110 | * |
---|
111 | */ |
---|
112 | |
---|
113 | Chain_Node *_Chain_Get( |
---|
114 | Chain_Control *the_chain |
---|
115 | ); |
---|
116 | |
---|
117 | /* |
---|
118 | * _Chain_Insert |
---|
119 | * |
---|
120 | * DESCRIPTION: |
---|
121 | * |
---|
122 | * This routine inserts the_node on a chain immediately following |
---|
123 | * after_node. It disables interrupts to insure the atomicity |
---|
124 | * of the extract operation. |
---|
125 | * |
---|
126 | */ |
---|
127 | |
---|
128 | void _Chain_Insert( |
---|
129 | Chain_Node *after_node, |
---|
130 | Chain_Node *the_node |
---|
131 | ); |
---|
132 | |
---|
133 | /* |
---|
134 | * _Chain_Append |
---|
135 | * |
---|
136 | * DESCRIPTION: |
---|
137 | * |
---|
138 | * This routine appends the_node onto the end of the_chain. |
---|
139 | * It disables interrupts to insure the atomicity of the |
---|
140 | * append operation. |
---|
141 | * |
---|
142 | */ |
---|
143 | |
---|
144 | void _Chain_Append( |
---|
145 | Chain_Control *the_chain, |
---|
146 | Chain_Node *the_node |
---|
147 | ); |
---|
148 | |
---|
149 | #ifndef __RTEMS_APPLICATION__ |
---|
150 | #include <rtems/score/chain.inl> |
---|
151 | #endif |
---|
152 | |
---|
153 | #ifdef __cplusplus |
---|
154 | } |
---|
155 | #endif |
---|
156 | |
---|
157 | #endif |
---|
158 | /* end of include file */ |
---|