1 | /* priority.inl |
---|
2 | * |
---|
3 | * This file contains the static inline implementation of all inlined |
---|
4 | * routines in the Priority Handler. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1997. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * Copyright assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may in |
---|
11 | * the file LICENSE in this distribution or at |
---|
12 | * http://www.OARcorp.com/rtems/license.html. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef __PRIORITY_inl |
---|
18 | #define __PRIORITY_inl |
---|
19 | |
---|
20 | #include <rtems/score/bitfield.h> |
---|
21 | |
---|
22 | /*PAGE |
---|
23 | * |
---|
24 | * _Priority_Handler_initialization |
---|
25 | * |
---|
26 | * DESCRIPTION: |
---|
27 | * |
---|
28 | * This routine performs the initialization necessary for this handler. |
---|
29 | */ |
---|
30 | |
---|
31 | RTEMS_INLINE_ROUTINE void _Priority_Handler_initialization( void ) |
---|
32 | { |
---|
33 | unsigned32 index; |
---|
34 | |
---|
35 | _Priority_Major_bit_map = 0; |
---|
36 | for ( index=0 ; index <16 ; index++ ) |
---|
37 | _Priority_Bit_map[ index ] = 0; |
---|
38 | } |
---|
39 | |
---|
40 | /*PAGE |
---|
41 | * |
---|
42 | * _Priority_Is_valid |
---|
43 | * |
---|
44 | * DESCRIPTION: |
---|
45 | * |
---|
46 | * This function returns TRUE if the_priority if valid for a |
---|
47 | * user task, and FALSE otherwise. |
---|
48 | */ |
---|
49 | |
---|
50 | RTEMS_INLINE_ROUTINE boolean _Priority_Is_valid ( |
---|
51 | Priority_Control the_priority |
---|
52 | ) |
---|
53 | { |
---|
54 | /* |
---|
55 | * Since PRIORITY_MINIMUM is 0 and priorities are stored unsigned, |
---|
56 | * then checking for less than 0 is unnecessary. |
---|
57 | */ |
---|
58 | |
---|
59 | return ( the_priority <= PRIORITY_MAXIMUM ); |
---|
60 | } |
---|
61 | |
---|
62 | /*PAGE |
---|
63 | * |
---|
64 | * _Priority_Major |
---|
65 | * |
---|
66 | * DESCRIPTION: |
---|
67 | * |
---|
68 | * This function returns the major portion of the_priority. |
---|
69 | */ |
---|
70 | |
---|
71 | RTEMS_INLINE_ROUTINE unsigned32 _Priority_Major ( |
---|
72 | Priority_Control the_priority |
---|
73 | ) |
---|
74 | { |
---|
75 | return ( the_priority / 16 ); |
---|
76 | } |
---|
77 | |
---|
78 | /*PAGE |
---|
79 | * |
---|
80 | * _Priority_Minor |
---|
81 | * |
---|
82 | * DESCRIPTION: |
---|
83 | * |
---|
84 | * This function returns the minor portion of the_priority. |
---|
85 | */ |
---|
86 | |
---|
87 | RTEMS_INLINE_ROUTINE unsigned32 _Priority_Minor ( |
---|
88 | Priority_Control the_priority |
---|
89 | ) |
---|
90 | { |
---|
91 | return ( the_priority % 16 ); |
---|
92 | } |
---|
93 | |
---|
94 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE ) |
---|
95 | |
---|
96 | /*PAGE |
---|
97 | * |
---|
98 | * _Priority_Mask |
---|
99 | * |
---|
100 | * DESCRIPTION: |
---|
101 | * |
---|
102 | * This function returns the mask associated with the major or minor |
---|
103 | * number passed to it. |
---|
104 | */ |
---|
105 | |
---|
106 | RTEMS_INLINE_ROUTINE unsigned32 _Priority_Mask ( |
---|
107 | unsigned32 bit_number |
---|
108 | ) |
---|
109 | { |
---|
110 | return (0x8000 >> bit_number); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | /*PAGE |
---|
115 | * |
---|
116 | * _Priority_Bits_index |
---|
117 | * |
---|
118 | * DESCRIPTION: |
---|
119 | * |
---|
120 | * This function translates the bit numbers returned by the bit scan |
---|
121 | * of a priority bit field into something suitable for use as |
---|
122 | * a major or minor component of a priority. |
---|
123 | */ |
---|
124 | |
---|
125 | RTEMS_INLINE_ROUTINE unsigned32 _Priority_Bits_index ( |
---|
126 | unsigned32 bit_number |
---|
127 | ) |
---|
128 | { |
---|
129 | return bit_number; |
---|
130 | } |
---|
131 | |
---|
132 | #endif |
---|
133 | |
---|
134 | /*PAGE |
---|
135 | * |
---|
136 | * _Priority_Add_to_bit_map |
---|
137 | * |
---|
138 | * DESCRIPTION: |
---|
139 | * |
---|
140 | * This routine uses the_priority_map to update the priority |
---|
141 | * bit maps to indicate that a thread has been readied. |
---|
142 | */ |
---|
143 | |
---|
144 | RTEMS_INLINE_ROUTINE void _Priority_Add_to_bit_map ( |
---|
145 | Priority_Information *the_priority_map |
---|
146 | ) |
---|
147 | { |
---|
148 | *the_priority_map->minor |= the_priority_map->ready_minor; |
---|
149 | _Priority_Major_bit_map |= the_priority_map->ready_major; |
---|
150 | } |
---|
151 | |
---|
152 | /*PAGE |
---|
153 | * |
---|
154 | * _Priority_Remove_from_bit_map |
---|
155 | * |
---|
156 | * DESCRIPTION: |
---|
157 | * |
---|
158 | * This routine uses the_priority_map to update the priority |
---|
159 | * bit maps to indicate that a thread has been removed from the |
---|
160 | * ready state. |
---|
161 | */ |
---|
162 | |
---|
163 | RTEMS_INLINE_ROUTINE void _Priority_Remove_from_bit_map ( |
---|
164 | Priority_Information *the_priority_map |
---|
165 | ) |
---|
166 | { |
---|
167 | *the_priority_map->minor &= the_priority_map->block_minor; |
---|
168 | if ( *the_priority_map->minor == 0 ) |
---|
169 | _Priority_Major_bit_map &= the_priority_map->block_major; |
---|
170 | } |
---|
171 | |
---|
172 | /*PAGE |
---|
173 | * |
---|
174 | * _Priority_Get_highest |
---|
175 | * |
---|
176 | * DESCRIPTION: |
---|
177 | * |
---|
178 | * This function returns the priority of the highest priority |
---|
179 | * ready thread. |
---|
180 | */ |
---|
181 | |
---|
182 | RTEMS_INLINE_ROUTINE Priority_Control _Priority_Get_highest( void ) |
---|
183 | { |
---|
184 | Priority_Bit_map_control minor; |
---|
185 | Priority_Bit_map_control major; |
---|
186 | |
---|
187 | _Bitfield_Find_first_bit( _Priority_Major_bit_map, major ); |
---|
188 | _Bitfield_Find_first_bit( _Priority_Bit_map[major], minor ); |
---|
189 | |
---|
190 | return (_Priority_Bits_index( major ) << 4) + |
---|
191 | _Priority_Bits_index( minor ); |
---|
192 | } |
---|
193 | |
---|
194 | /*PAGE |
---|
195 | * |
---|
196 | * _Priority_Initialize_information |
---|
197 | * |
---|
198 | * DESCRIPTION: |
---|
199 | * |
---|
200 | * This routine initializes the_priority_map so that it |
---|
201 | * contains the information necessary to manage a thread |
---|
202 | * at new_priority. |
---|
203 | */ |
---|
204 | |
---|
205 | RTEMS_INLINE_ROUTINE void _Priority_Initialize_information( |
---|
206 | Priority_Information *the_priority_map, |
---|
207 | Priority_Control new_priority |
---|
208 | ) |
---|
209 | { |
---|
210 | Priority_Bit_map_control major; |
---|
211 | Priority_Bit_map_control minor; |
---|
212 | Priority_Bit_map_control mask; |
---|
213 | |
---|
214 | major = _Priority_Major( new_priority ); |
---|
215 | minor = _Priority_Minor( new_priority ); |
---|
216 | |
---|
217 | the_priority_map->minor = |
---|
218 | &_Priority_Bit_map[ _Priority_Bits_index(major) ]; |
---|
219 | |
---|
220 | mask = _Priority_Mask( major ); |
---|
221 | the_priority_map->ready_major = mask; |
---|
222 | the_priority_map->block_major = ~mask; |
---|
223 | |
---|
224 | mask = _Priority_Mask( minor ); |
---|
225 | the_priority_map->ready_minor = mask; |
---|
226 | the_priority_map->block_minor = ~mask; |
---|
227 | } |
---|
228 | |
---|
229 | /*PAGE |
---|
230 | * |
---|
231 | * _Priority_Is_group_empty |
---|
232 | * |
---|
233 | * DESCRIPTION: |
---|
234 | * |
---|
235 | * This function returns TRUE if the priority GROUP is empty, and |
---|
236 | * FALSE otherwise. |
---|
237 | */ |
---|
238 | |
---|
239 | RTEMS_INLINE_ROUTINE boolean _Priority_Is_group_empty ( |
---|
240 | Priority_Control the_priority |
---|
241 | ) |
---|
242 | { |
---|
243 | return the_priority == 0; |
---|
244 | } |
---|
245 | |
---|
246 | #endif |
---|
247 | /* end of include file */ |
---|