1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines in the Priority Handler Bit Map Implementation |
---|
5 | * |
---|
6 | * This file contains the static inline implementation of all inlined |
---|
7 | * routines in the Priority Handler bit map implementation |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2010. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_PRIORITYBITMAPIMPL_H |
---|
20 | #define _RTEMS_SCORE_PRIORITYBITMAPIMPL_H |
---|
21 | |
---|
22 | #include <rtems/score/prioritybitmap.h> |
---|
23 | |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** |
---|
31 | * @addtogroup ScorePriority |
---|
32 | */ |
---|
33 | /**@{**/ |
---|
34 | |
---|
35 | /** |
---|
36 | * This table is used by the generic bitfield routines to perform |
---|
37 | * a highly optimized bit scan without the use of special CPU |
---|
38 | * instructions. |
---|
39 | */ |
---|
40 | extern const unsigned char _Bitfield_Leading_zeros[256]; |
---|
41 | |
---|
42 | /** |
---|
43 | * @brief Gets the @a _bit_number of the first bit set in the specified value. |
---|
44 | * |
---|
45 | * This routine returns the @a _bit_number of the first bit set |
---|
46 | * in the specified value. The correspondence between @a _bit_number |
---|
47 | * and actual bit position is processor dependent. The search for |
---|
48 | * the first bit set may run from most to least significant bit |
---|
49 | * or vice-versa. |
---|
50 | * |
---|
51 | * @param[in] _value is the value to bit scan. |
---|
52 | * @param[in] _bit_number is the position of the first bit set. |
---|
53 | * |
---|
54 | * @note This routine is used when the executing thread is removed |
---|
55 | * from the ready state and, as a result, its performance has a |
---|
56 | * significant impact on the performance of the executive as a whole. |
---|
57 | * |
---|
58 | * @note This routine must be a macro because if a CPU specific version |
---|
59 | * is used it will most likely use inline assembly. |
---|
60 | */ |
---|
61 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
62 | #define _Bitfield_Find_first_bit( _value, _bit_number ) \ |
---|
63 | _CPU_Bitfield_Find_first_bit( _value, _bit_number ) |
---|
64 | #else |
---|
65 | #define _Bitfield_Find_first_bit( _value, _bit_number ) \ |
---|
66 | { \ |
---|
67 | unsigned int __value = (_value); \ |
---|
68 | const unsigned char *__p = _Bitfield_Leading_zeros; \ |
---|
69 | \ |
---|
70 | if ( __value < 0x100 ) \ |
---|
71 | (_bit_number) = (Priority_bit_map_Word)( __p[ __value ] + 8 ); \ |
---|
72 | else \ |
---|
73 | (_bit_number) = (Priority_bit_map_Word)( __p[ __value >> 8 ] ); \ |
---|
74 | } |
---|
75 | #endif |
---|
76 | |
---|
77 | /** |
---|
78 | * @brief Returns the priority bit mask for the specified major or minor bit |
---|
79 | * number. |
---|
80 | * |
---|
81 | * @param bit_number The bit number for which we need a mask. |
---|
82 | * |
---|
83 | * @return The priority bit mask. |
---|
84 | */ |
---|
85 | RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask( |
---|
86 | unsigned int bit_number |
---|
87 | ) |
---|
88 | { |
---|
89 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
90 | return _CPU_Priority_Mask( bit_number ); |
---|
91 | #else |
---|
92 | return (Priority_bit_map_Word) ( 0x8000u >> bit_number ); |
---|
93 | #endif |
---|
94 | } |
---|
95 | |
---|
96 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
97 | /** |
---|
98 | * This method returns the bit index position for the specified priority. |
---|
99 | * |
---|
100 | * @param[in] _priority is the priority for which we need the index. |
---|
101 | * |
---|
102 | * @retval This method returns the array index into the priority bit map. |
---|
103 | * |
---|
104 | * @note This may simply be a pass through to a CPU dependent implementation. |
---|
105 | */ |
---|
106 | #define _Priority_Bits_index( _priority ) \ |
---|
107 | _CPU_Priority_bits_index( _priority ) |
---|
108 | #endif |
---|
109 | |
---|
110 | /** |
---|
111 | * This function returns the major portion of the_priority. |
---|
112 | */ |
---|
113 | |
---|
114 | RTEMS_INLINE_ROUTINE unsigned int _Priority_Major( unsigned int the_priority ) |
---|
115 | { |
---|
116 | return the_priority / 16; |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * This function returns the minor portion of the_priority. |
---|
121 | */ |
---|
122 | |
---|
123 | RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor( unsigned int the_priority ) |
---|
124 | { |
---|
125 | return the_priority % 16; |
---|
126 | } |
---|
127 | |
---|
128 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE ) |
---|
129 | |
---|
130 | /** |
---|
131 | * This function translates the bit numbers returned by the bit scan |
---|
132 | * of a priority bit field into something suitable for use as |
---|
133 | * a major or minor component of a priority. |
---|
134 | */ |
---|
135 | |
---|
136 | RTEMS_INLINE_ROUTINE unsigned int _Priority_Bits_index( |
---|
137 | unsigned int bit_number |
---|
138 | ) |
---|
139 | { |
---|
140 | return bit_number; |
---|
141 | } |
---|
142 | |
---|
143 | #endif |
---|
144 | |
---|
145 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize( |
---|
146 | Priority_bit_map_Control *bit_map |
---|
147 | ) |
---|
148 | { |
---|
149 | memset( bit_map, 0, sizeof( *bit_map ) ); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * Priority Queue implemented by bit map |
---|
154 | */ |
---|
155 | |
---|
156 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add ( |
---|
157 | Priority_bit_map_Control *bit_map, |
---|
158 | Priority_bit_map_Information *bit_map_info |
---|
159 | ) |
---|
160 | { |
---|
161 | *bit_map_info->minor |= bit_map_info->ready_minor; |
---|
162 | bit_map->major_bit_map |= bit_map_info->ready_major; |
---|
163 | } |
---|
164 | |
---|
165 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove ( |
---|
166 | Priority_bit_map_Control *bit_map, |
---|
167 | Priority_bit_map_Information *bit_map_info |
---|
168 | ) |
---|
169 | { |
---|
170 | *bit_map_info->minor &= bit_map_info->block_minor; |
---|
171 | if ( *bit_map_info->minor == 0 ) |
---|
172 | bit_map->major_bit_map &= bit_map_info->block_major; |
---|
173 | } |
---|
174 | |
---|
175 | RTEMS_INLINE_ROUTINE unsigned int _Priority_bit_map_Get_highest( |
---|
176 | const Priority_bit_map_Control *bit_map |
---|
177 | ) |
---|
178 | { |
---|
179 | unsigned int minor; |
---|
180 | unsigned int major; |
---|
181 | |
---|
182 | /* Avoid problems with some inline ASM statements */ |
---|
183 | unsigned int tmp; |
---|
184 | |
---|
185 | tmp = bit_map->major_bit_map; |
---|
186 | _Bitfield_Find_first_bit( tmp, major ); |
---|
187 | |
---|
188 | tmp = bit_map->bit_map[ major ]; |
---|
189 | _Bitfield_Find_first_bit( tmp, minor ); |
---|
190 | |
---|
191 | return (_Priority_Bits_index( major ) << 4) + |
---|
192 | _Priority_Bits_index( minor ); |
---|
193 | } |
---|
194 | |
---|
195 | RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty( |
---|
196 | const Priority_bit_map_Control *bit_map |
---|
197 | ) |
---|
198 | { |
---|
199 | return bit_map->major_bit_map == 0; |
---|
200 | } |
---|
201 | |
---|
202 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information( |
---|
203 | Priority_bit_map_Control *bit_map, |
---|
204 | Priority_bit_map_Information *bit_map_info, |
---|
205 | unsigned int new_priority |
---|
206 | ) |
---|
207 | { |
---|
208 | unsigned int major; |
---|
209 | unsigned int minor; |
---|
210 | Priority_bit_map_Word mask; |
---|
211 | |
---|
212 | major = _Priority_Major( new_priority ); |
---|
213 | minor = _Priority_Minor( new_priority ); |
---|
214 | |
---|
215 | bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ]; |
---|
216 | |
---|
217 | mask = _Priority_Mask( major ); |
---|
218 | bit_map_info->ready_major = mask; |
---|
219 | bit_map_info->block_major = (Priority_bit_map_Word) ~mask; |
---|
220 | |
---|
221 | mask = _Priority_Mask( minor ); |
---|
222 | bit_map_info->ready_minor = mask; |
---|
223 | bit_map_info->block_minor = (Priority_bit_map_Word) ~mask; |
---|
224 | } |
---|
225 | |
---|
226 | /** @} */ |
---|
227 | |
---|
228 | #ifdef __cplusplus |
---|
229 | } |
---|
230 | #endif |
---|
231 | |
---|
232 | #endif |
---|
233 | /* end of include file */ |
---|