source: rtems/doc/tools/bmenu/chain.c @ 39e50b3f

4.104.114.84.95
Last change on this file since 39e50b3f was 39e50b3f, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/23/03 at 19:11:46

2003-11-23 Ralf Corsepius <corsepiu@…>

  • system.h: Remove USE_INLINES.
  • chain.c: Remove USE_INLINES.
  • Property mode set to 100644
File size: 4.1 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
60 *
61 *  This kernel routine returns a pointer to a node taken from the
62 *  given chain.
63 *
64 *  Input parameters:
65 *    the_chain - pointer to chain header
66 *
67 *  Output parameters:
68 *    return_node - pointer to node in chain allocated
69 *    CHAIN_END   - if no nodes available
70 *
71 *  INTERRUPT LATENCY:
72 *    only case
73 */
74
75Chain_Node *_Chain_Get(
76  Chain_Control *the_chain
77)
78{
79  ISR_Level          level;
80  Chain_Node *return_node;
81
82  return_node = NULL;
83  _ISR_Disable( level );
84    if ( !_Chain_Is_empty( the_chain ) )
85      return_node = _Chain_Get_first_unprotected( the_chain );
86  _ISR_Enable( level );
87  return return_node;
88}
89
90/*PAGE
91 *
92 *  _Chain_Append
93 *
94 *  This kernel routine puts a node on the end of the specified chain.
95 *
96 *  Input parameters:
97 *    the_chain - pointer to chain header
98 *    node      - address of node to put at rear of chain
99 *
100 *  Output parameters:  NONE
101 *
102 *  INTERRUPT LATENCY:
103 *    only case
104 */
105
106void _Chain_Append(
107  Chain_Control *the_chain,
108  Chain_Node    *node
109)
110{
111  ISR_Level level;
112
113  _ISR_Disable( level );
114    _Chain_Append_unprotected( the_chain, node );
115  _ISR_Enable( level );
116}
117
118/*PAGE
119 *
120 *  _Chain_Extract
121 *
122 *  This kernel routine deletes the given node from a chain.
123 *
124 *  Input parameters:
125 *    node - pointer to node in chain to be deleted
126 *
127 *  Output parameters:  NONE
128 *
129 *  INTERRUPT LATENCY:
130 *    only case
131 */
132
133void _Chain_Extract(
134  Chain_Node *node
135)
136{
137  ISR_Level level;
138
139  _ISR_Disable( level );
140    _Chain_Extract_unprotected( node );
141  _ISR_Enable( level );
142}
143
144/*PAGE
145 *
146 *  _Chain_Insert
147 *
148 *  This kernel routine inserts a given node after a specified node
149 *  a requested chain.
150 *
151 *  Input parameters:
152 *    after_node - pointer to node in chain to be inserted after
153 *    node       - pointer to node to be inserted
154 *
155 *  Output parameters:  NONE
156 *
157 *  INTERRUPT LATENCY:
158 *    only case
159 */
160
161void _Chain_Insert(
162  Chain_Node *after_node,
163  Chain_Node *node
164)
165{
166  ISR_Level level;
167
168  _ISR_Disable( level );
169    _Chain_Insert_unprotected( after_node, node );
170  _ISR_Enable( level );
171}
172
173/*PAGE
174 *
175 *  _Chain_Insert_chain
176 *
177 *  This routine inserts a chain after the specified node in another
178 *  chain. It is assumed that the insert after node is not on the
179 *  second chain.
180 *
181 *  Input parameters:
182 *    insert_after - insert the chain after this node
183 *    to_insert    - the chain to insert
184 */
185 
186void _Chain_Insert_chain(
187  Chain_Node    *insert_after,
188  Chain_Control *to_insert
189)
190{
191  Chain_Node *first;
192  Chain_Node *last;
193  Chain_Node *insert_after_next;
194
195  first = to_insert->first;
196  last = to_insert->last;
197
198  insert_after_next = insert_after->next;
199
200  insert_after->next = first;
201  first->previous    = insert_after;
202
203  insert_after_next->previous = last;
204  last->next                  = insert_after_next;
205
206  _Chain_Initialize_empty( to_insert );
207}
Note: See TracBrowser for help on using the repository browser.