RTEMS
prioritybitmapimpl.h
Go to the documentation of this file.
1 
12 /*
13  * COPYRIGHT (c) 1989-2010.
14  * On-Line Applications Research Corporation (OAR).
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_PRIORITYBITMAPIMPL_H
22 #define _RTEMS_SCORE_PRIORITYBITMAPIMPL_H
23 
25 
26 #include <string.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
43 extern const unsigned char _Bitfield_Leading_zeros[256];
44 
59  unsigned int value
60 )
61 {
62  unsigned int bit_number;
63 
64 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
65  _CPU_Bitfield_Find_first_bit( value, bit_number );
66 #elif defined(__GNUC__)
67  bit_number = (unsigned int) __builtin_clz( value )
68  - __SIZEOF_INT__ * __CHAR_BIT__ + 16;
69 #else
70  if ( value < 0x100 ) {
71  bit_number = _Bitfield_Leading_zeros[ value ] + 8;
72  } else { \
73  bit_number = _Bitfield_Leading_zeros[ value >> 8 ];
74  }
75 #endif
76 
77  return bit_number;
78 }
79 
88 RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask(
89  unsigned int bit_number
90 )
91 {
92 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
93  return _CPU_Priority_Mask( bit_number );
94 #else
95  return (Priority_bit_map_Word) ( 0x8000u >> bit_number );
96 #endif
97 }
98 
108  unsigned int bit_number
109 )
110 {
111 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
112  return _CPU_Priority_bits_index( bit_number );
113 #else
114  return bit_number;
115 #endif
116 }
117 
125 RTEMS_INLINE_ROUTINE unsigned int _Priority_Major( unsigned int the_priority )
126 {
127  return the_priority / 16;
128 }
129 
137 RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor( unsigned int the_priority )
138 {
139  return the_priority % 16;
140 }
141 
148  Priority_bit_map_Control *bit_map
149 )
150 {
151  memset( bit_map, 0, sizeof( *bit_map ) );
152 }
153 
163  Priority_bit_map_Control *bit_map,
164  Priority_bit_map_Information *bit_map_info
165 )
166 {
167  *bit_map_info->minor |= bit_map_info->ready_minor;
168  bit_map->major_bit_map |= bit_map_info->ready_major;
169 }
170 
180  Priority_bit_map_Control *bit_map,
181  Priority_bit_map_Information *bit_map_info
182 )
183 {
184  *bit_map_info->minor &= bit_map_info->block_minor;
185  if ( *bit_map_info->minor == 0 )
186  bit_map->major_bit_map &= bit_map_info->block_major;
187 }
188 
197  const Priority_bit_map_Control *bit_map
198 )
199 {
200  unsigned int minor;
201  unsigned int major;
202 
203  major = _Bitfield_Find_first_bit( bit_map->major_bit_map );
204  minor = _Bitfield_Find_first_bit( bit_map->bit_map[ major ] );
205 
206  return (_Priority_Bits_index( major ) << 4) +
207  _Priority_Bits_index( minor );
208 }
209 
219  const Priority_bit_map_Control *bit_map
220 )
221 {
222  return bit_map->major_bit_map == 0;
223 }
224 
235  Priority_bit_map_Control *bit_map,
236  Priority_bit_map_Information *bit_map_info,
237  unsigned int new_priority
238 )
239 {
240  unsigned int major;
241  unsigned int minor;
242  Priority_bit_map_Word mask;
243 
244  major = _Priority_Major( new_priority );
245  minor = _Priority_Minor( new_priority );
246 
247  bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
248 
249  mask = _Priority_Mask( major );
250  bit_map_info->ready_major = mask;
251  bit_map_info->block_major = (Priority_bit_map_Word) ~mask;
252 
253  mask = _Priority_Mask( minor );
254  bit_map_info->ready_minor = mask;
255  bit_map_info->block_minor = (Priority_bit_map_Word) ~mask;
256 }
257 
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif
265 /* end of include file */
RTEMS_INLINE_ROUTINE unsigned int _Priority_Major(unsigned int the_priority)
Returns the major portion of the_priority.
RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add(Priority_bit_map_Control *bit_map, Priority_bit_map_Information *bit_map_info)
Adds Priority queue bit map information.
Priority_bit_map_Word bit_map[16]
Each bit in the bit map indicates whether or not there are threads ready at a particular priority...
Priority_bit_map_Word ready_major
RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove(Priority_bit_map_Control *bit_map, Priority_bit_map_Information *bit_map_info)
Removes Priority queue bit map information.
RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize(Priority_bit_map_Control *bit_map)
Initializes a bit map.
Priority_bit_map_Word block_major
Priority_bit_map_Word block_minor
Priority_bit_map_Word * minor
RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor(unsigned int the_priority)
Returns the minor portion of the_priority.
RTEMS_INLINE_ROUTINE unsigned int _Priority_bit_map_Get_highest(const Priority_bit_map_Control *bit_map)
Gets highest portion of Priority queue bit map.
Priority_bit_map_Word ready_minor
Priority_bit_map_Word major_bit_map
Each sixteen bit entry in this word is associated with one of the sixteen entries in the bit map...
Manipulation Routines for the Bitmap Priority Queue Implementation.
RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask(unsigned int bit_number)
Returns the priority bit mask for the specified major or minor bit number.
RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(Priority_bit_map_Control *bit_map, Priority_bit_map_Information *bit_map_info, unsigned int new_priority)
Initializes the bit map information.
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
const unsigned char _Bitfield_Leading_zeros[256]
RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty(const Priority_bit_map_Control *bit_map)
Checks if the Priority queue bit map is empty.
RTEMS_INLINE_ROUTINE unsigned int _Priority_Bits_index(unsigned int bit_number)
Returns the bit index position for the specified major or minor bit number.
RTEMS_INLINE_ROUTINE unsigned int _Bitfield_Find_first_bit(unsigned int value)
Returns the bit number of the first bit set in the specified value.