source: rtems/c/src/exec/score/src/chain.c @ df49c60

4.104.114.84.95
Last change on this file since df49c60 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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