source: rtems/doc/tools/bmenu/chain.c @ 6449498

4.104.114.84.95
Last change on this file since 6449498 was 6449498, checked in by Joel Sherrill <joel.sherrill@…>, on 01/17/02 at 21:47:47

2001-01-17 Joel Sherrill <joel@…>

  • SUPPORT, LICENSE: New files.
  • Numerous files touched as part of merging the 4.5 branch onto the mainline development trunk and ensuring that the script that cuts snapshots and releases works on the documentation.
  • Property mode set to 100644
File size: 4.5 KB
Line 
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#include "isr.h"
15
16/*PAGE
17 *
18 *  _Chain_Initialize
19 *
20 *  This kernel routine initializes a doubly linked chain.
21 *
22 *  Input parameters:
23 *    the_chain        - pointer to chain header
24 *    starting_address - starting address of first node
25 *    number_nodes     - number of nodes in chain
26 *    node_size        - size of node in bytes
27 *
28 *  Output parameters:  NONE
29 */
30
31void _Chain_Initialize(
32  Chain_Control *the_chain,
33  void           *starting_address,
34  unsigned32     number_nodes,
35  unsigned32     node_size
36)
37{
38  unsigned32  count;
39  Chain_Node *current;
40  Chain_Node *next;
41
42  count                     = number_nodes;
43  current                   = _Chain_Head( the_chain );
44  the_chain->permanent_null = NULL;
45  next                      = (Chain_Node *)starting_address;
46  while ( count-- ) {
47    current->next  = next;
48    next->previous = current;
49    current        = next;
50    next           = (Chain_Node *)
51                        _Addresses_Add_offset( (void *) next, node_size );
52  }
53  current->next    = _Chain_Tail( the_chain );
54  the_chain->last  = current;
55}
56
57/*PAGE
58 *
59 *  _Chain_Get_first_unprotected
60 */
61
62#ifndef USE_INLINES
63STATIC INLINE Chain_Node *_Chain_Get_first_unprotected(
64  Chain_Control *the_chain
65)
66{
67  Chain_Node  *return_node;
68  Chain_Node  *new_first;
69
70  return_node         = the_chain->first;
71  new_first           = return_node->next;
72  the_chain->first    = new_first;
73  new_first->previous = _Chain_Head( the_chain );
74
75  return return_node;
76}
77#endif   /* USE_INLINES */
78
79/*PAGE
80 *
81 *  _Chain_Get
82 *
83 *  This kernel routine returns a pointer to a node taken from the
84 *  given chain.
85 *
86 *  Input parameters:
87 *    the_chain - pointer to chain header
88 *
89 *  Output parameters:
90 *    return_node - pointer to node in chain allocated
91 *    CHAIN_END   - if no nodes available
92 *
93 *  INTERRUPT LATENCY:
94 *    only case
95 */
96
97Chain_Node *_Chain_Get(
98  Chain_Control *the_chain
99)
100{
101  ISR_Level          level;
102  Chain_Node *return_node;
103
104  return_node = NULL;
105  _ISR_Disable( level );
106    if ( !_Chain_Is_empty( the_chain ) )
107      return_node = _Chain_Get_first_unprotected( the_chain );
108  _ISR_Enable( level );
109  return return_node;
110}
111
112/*PAGE
113 *
114 *  _Chain_Append
115 *
116 *  This kernel routine puts a node on the end of the specified chain.
117 *
118 *  Input parameters:
119 *    the_chain - pointer to chain header
120 *    node      - address of node to put at rear of chain
121 *
122 *  Output parameters:  NONE
123 *
124 *  INTERRUPT LATENCY:
125 *    only case
126 */
127
128void _Chain_Append(
129  Chain_Control *the_chain,
130  Chain_Node    *node
131)
132{
133  ISR_Level level;
134
135  _ISR_Disable( level );
136    _Chain_Append_unprotected( the_chain, node );
137  _ISR_Enable( level );
138}
139
140/*PAGE
141 *
142 *  _Chain_Extract
143 *
144 *  This kernel routine deletes the given node from a chain.
145 *
146 *  Input parameters:
147 *    node - pointer to node in chain to be deleted
148 *
149 *  Output parameters:  NONE
150 *
151 *  INTERRUPT LATENCY:
152 *    only case
153 */
154
155void _Chain_Extract(
156  Chain_Node *node
157)
158{
159  ISR_Level level;
160
161  _ISR_Disable( level );
162    _Chain_Extract_unprotected( node );
163  _ISR_Enable( level );
164}
165
166/*PAGE
167 *
168 *  _Chain_Insert
169 *
170 *  This kernel routine inserts a given node after a specified node
171 *  a requested chain.
172 *
173 *  Input parameters:
174 *    after_node - pointer to node in chain to be inserted after
175 *    node       - pointer to node to be inserted
176 *
177 *  Output parameters:  NONE
178 *
179 *  INTERRUPT LATENCY:
180 *    only case
181 */
182
183void _Chain_Insert(
184  Chain_Node *after_node,
185  Chain_Node *node
186)
187{
188  ISR_Level level;
189
190  _ISR_Disable( level );
191    _Chain_Insert_unprotected( after_node, node );
192  _ISR_Enable( level );
193}
194
195/*PAGE
196 *
197 *  _Chain_Insert_chain
198 *
199 *  This routine inserts a chain after the specified node in another
200 *  chain. It is assumed that the insert after node is not on the
201 *  second chain.
202 *
203 *  Input parameters:
204 *    insert_after - insert the chain after this node
205 *    to_insert    - the chain to insert
206 */
207 
208void _Chain_Insert_chain(
209  Chain_Node    *insert_after,
210  Chain_Control *to_insert
211)
212{
213  Chain_Node *first;
214  Chain_Node *last;
215  Chain_Node *insert_after_next;
216
217  first = to_insert->first;
218  last = to_insert->last;
219
220  insert_after_next = insert_after->next;
221
222  insert_after->next = first;
223  first->previous    = insert_after;
224
225  insert_after_next->previous = last;
226  last->next                  = insert_after_next;
227
228  _Chain_Initialize_empty( to_insert );
229}
Note: See TracBrowser for help on using the repository browser.