1 | /* |
---|
2 | * Chain Handler |
---|
3 | * |
---|
4 | * NOTE: |
---|
5 | * |
---|
6 | * The order of this file is to allow proper compilation due to the |
---|
7 | * order of inlining required by the compiler. |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-1998. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * Copyright assigned to U.S. Government, 1994. |
---|
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.OARcorp.com/rtems/license.html. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include <rtems/system.h> |
---|
21 | #include <rtems/score/address.h> |
---|
22 | #include <rtems/score/chain.h> |
---|
23 | #include <rtems/score/isr.h> |
---|
24 | |
---|
25 | /*PAGE |
---|
26 | * |
---|
27 | * _Chain_Initialize |
---|
28 | * |
---|
29 | * This kernel routine initializes a doubly linked chain. |
---|
30 | * |
---|
31 | * Input parameters: |
---|
32 | * the_chain - pointer to chain header |
---|
33 | * starting_address - starting address of first node |
---|
34 | * number_nodes - number of nodes in chain |
---|
35 | * node_size - size of node in bytes |
---|
36 | * |
---|
37 | * Output parameters: NONE |
---|
38 | */ |
---|
39 | |
---|
40 | void _Chain_Initialize( |
---|
41 | Chain_Control *the_chain, |
---|
42 | void *starting_address, |
---|
43 | unsigned32 number_nodes, |
---|
44 | unsigned32 node_size |
---|
45 | ) |
---|
46 | { |
---|
47 | unsigned32 count; |
---|
48 | Chain_Node *current; |
---|
49 | Chain_Node *next; |
---|
50 | |
---|
51 | count = number_nodes; |
---|
52 | current = _Chain_Head( the_chain ); |
---|
53 | the_chain->permanent_null = NULL; |
---|
54 | next = (Chain_Node *)starting_address; |
---|
55 | while ( count-- ) { |
---|
56 | current->next = next; |
---|
57 | next->previous = current; |
---|
58 | current = next; |
---|
59 | next = (Chain_Node *) |
---|
60 | _Addresses_Add_offset( (void *) next, node_size ); |
---|
61 | } |
---|
62 | current->next = _Chain_Tail( the_chain ); |
---|
63 | the_chain->last = current; |
---|
64 | } |
---|
65 | |
---|
66 | /*PAGE |
---|
67 | * |
---|
68 | * _Chain_Get_first_unprotected |
---|
69 | */ |
---|
70 | |
---|
71 | #ifndef USE_INLINES |
---|
72 | Chain_Node *_Chain_Get_first_unprotected( |
---|
73 | Chain_Control *the_chain |
---|
74 | ) |
---|
75 | { |
---|
76 | Chain_Node *return_node; |
---|
77 | Chain_Node *new_first; |
---|
78 | |
---|
79 | return_node = the_chain->first; |
---|
80 | new_first = return_node->next; |
---|
81 | the_chain->first = new_first; |
---|
82 | new_first->previous = _Chain_Head( the_chain ); |
---|
83 | |
---|
84 | return return_node; |
---|
85 | } |
---|
86 | #endif /* USE_INLINES */ |
---|
87 | |
---|
88 | /*PAGE |
---|
89 | * |
---|
90 | * _Chain_Get |
---|
91 | * |
---|
92 | * This kernel routine returns a pointer to a node taken from the |
---|
93 | * given chain. |
---|
94 | * |
---|
95 | * Input parameters: |
---|
96 | * the_chain - pointer to chain header |
---|
97 | * |
---|
98 | * Output parameters: |
---|
99 | * return_node - pointer to node in chain allocated |
---|
100 | * CHAIN_END - if no nodes available |
---|
101 | * |
---|
102 | * INTERRUPT LATENCY: |
---|
103 | * only case |
---|
104 | */ |
---|
105 | |
---|
106 | Chain_Node *_Chain_Get( |
---|
107 | Chain_Control *the_chain |
---|
108 | ) |
---|
109 | { |
---|
110 | ISR_Level level; |
---|
111 | Chain_Node *return_node; |
---|
112 | |
---|
113 | return_node = NULL; |
---|
114 | _ISR_Disable( level ); |
---|
115 | if ( !_Chain_Is_empty( the_chain ) ) |
---|
116 | return_node = _Chain_Get_first_unprotected( the_chain ); |
---|
117 | _ISR_Enable( level ); |
---|
118 | return return_node; |
---|
119 | } |
---|
120 | |
---|
121 | /*PAGE |
---|
122 | * |
---|
123 | * _Chain_Append |
---|
124 | * |
---|
125 | * This kernel routine puts a node on the end of the specified chain. |
---|
126 | * |
---|
127 | * Input parameters: |
---|
128 | * the_chain - pointer to chain header |
---|
129 | * node - address of node to put at rear of chain |
---|
130 | * |
---|
131 | * Output parameters: NONE |
---|
132 | * |
---|
133 | * INTERRUPT LATENCY: |
---|
134 | * only case |
---|
135 | */ |
---|
136 | |
---|
137 | void _Chain_Append( |
---|
138 | Chain_Control *the_chain, |
---|
139 | Chain_Node *node |
---|
140 | ) |
---|
141 | { |
---|
142 | ISR_Level level; |
---|
143 | |
---|
144 | _ISR_Disable( level ); |
---|
145 | _Chain_Append_unprotected( the_chain, node ); |
---|
146 | _ISR_Enable( level ); |
---|
147 | } |
---|
148 | |
---|
149 | /*PAGE |
---|
150 | * |
---|
151 | * _Chain_Extract |
---|
152 | * |
---|
153 | * This kernel routine deletes the given node from a chain. |
---|
154 | * |
---|
155 | * Input parameters: |
---|
156 | * node - pointer to node in chain to be deleted |
---|
157 | * |
---|
158 | * Output parameters: NONE |
---|
159 | * |
---|
160 | * INTERRUPT LATENCY: |
---|
161 | * only case |
---|
162 | */ |
---|
163 | |
---|
164 | void _Chain_Extract( |
---|
165 | Chain_Node *node |
---|
166 | ) |
---|
167 | { |
---|
168 | ISR_Level level; |
---|
169 | |
---|
170 | _ISR_Disable( level ); |
---|
171 | _Chain_Extract_unprotected( node ); |
---|
172 | _ISR_Enable( level ); |
---|
173 | } |
---|
174 | |
---|
175 | /*PAGE |
---|
176 | * |
---|
177 | * _Chain_Insert |
---|
178 | * |
---|
179 | * This kernel routine inserts a given node after a specified node |
---|
180 | * a requested chain. |
---|
181 | * |
---|
182 | * Input parameters: |
---|
183 | * after_node - pointer to node in chain to be inserted after |
---|
184 | * node - pointer to node to be inserted |
---|
185 | * |
---|
186 | * Output parameters: NONE |
---|
187 | * |
---|
188 | * INTERRUPT LATENCY: |
---|
189 | * only case |
---|
190 | */ |
---|
191 | |
---|
192 | void _Chain_Insert( |
---|
193 | Chain_Node *after_node, |
---|
194 | Chain_Node *node |
---|
195 | ) |
---|
196 | { |
---|
197 | ISR_Level level; |
---|
198 | |
---|
199 | _ISR_Disable( level ); |
---|
200 | _Chain_Insert_unprotected( after_node, node ); |
---|
201 | _ISR_Enable( level ); |
---|
202 | } |
---|