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