RTEMS  5.0.0
prioritybitmapimpl.h
Go to the documentation of this file.
1 
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 
23 
24 #include <string.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
40 extern const unsigned char _Bitfield_Leading_zeros[256];
41 
56  unsigned int value
57 )
58 {
59  unsigned int bit_number;
60 
61 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
62  _CPU_Bitfield_Find_first_bit( value, bit_number );
63 #elif defined(__GNUC__)
64  bit_number = (unsigned int) __builtin_clz( value )
65  - __SIZEOF_INT__ * __CHAR_BIT__ + 16;
66 #else
67  if ( value < 0x100 ) {
68  bit_number = _Bitfield_Leading_zeros[ value ] + 8;
69  } else { \
70  bit_number = _Bitfield_Leading_zeros[ value >> 8 ];
71  }
72 #endif
73 
74  return bit_number;
75 }
76 
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 
105  unsigned int bit_number
106 )
107 {
108 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
109  return _CPU_Priority_bits_index( bit_number );
110 #else
111  return bit_number;
112 #endif
113 }
114 
119 RTEMS_INLINE_ROUTINE unsigned int _Priority_Major( unsigned int the_priority )
120 {
121  return the_priority / 16;
122 }
123 
128 RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor( unsigned int the_priority )
129 {
130  return the_priority % 16;
131 }
132 
133 RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize(
134  Priority_bit_map_Control *bit_map
135 )
136 {
137  memset( bit_map, 0, sizeof( *bit_map ) );
138 }
139 
145  Priority_bit_map_Control *bit_map,
146  Priority_bit_map_Information *bit_map_info
147 )
148 {
149  *bit_map_info->minor |= bit_map_info->ready_minor;
150  bit_map->major_bit_map |= bit_map_info->ready_major;
151 }
152 
153 RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove (
154  Priority_bit_map_Control *bit_map,
155  Priority_bit_map_Information *bit_map_info
156 )
157 {
158  *bit_map_info->minor &= bit_map_info->block_minor;
159  if ( *bit_map_info->minor == 0 )
160  bit_map->major_bit_map &= bit_map_info->block_major;
161 }
162 
163 RTEMS_INLINE_ROUTINE unsigned int _Priority_bit_map_Get_highest(
164  const Priority_bit_map_Control *bit_map
165 )
166 {
167  unsigned int minor;
168  unsigned int major;
169 
170  major = _Bitfield_Find_first_bit( bit_map->major_bit_map );
171  minor = _Bitfield_Find_first_bit( bit_map->bit_map[ major ] );
172 
173  return (_Priority_Bits_index( major ) << 4) +
174  _Priority_Bits_index( minor );
175 }
176 
177 RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty(
178  const Priority_bit_map_Control *bit_map
179 )
180 {
181  return bit_map->major_bit_map == 0;
182 }
183 
184 RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(
185  Priority_bit_map_Control *bit_map,
186  Priority_bit_map_Information *bit_map_info,
187  unsigned int new_priority
188 )
189 {
190  unsigned int major;
191  unsigned int minor;
192  Priority_bit_map_Word mask;
193 
194  major = _Priority_Major( new_priority );
195  minor = _Priority_Minor( new_priority );
196 
197  bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
198 
199  mask = _Priority_Mask( major );
200  bit_map_info->ready_major = mask;
201  bit_map_info->block_major = (Priority_bit_map_Word) ~mask;
202 
203  mask = _Priority_Mask( minor );
204  bit_map_info->ready_minor = mask;
205  bit_map_info->block_minor = (Priority_bit_map_Word) ~mask;
206 }
207 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif
215 /* end of include file */
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.
Definition: prioritybitmapimpl.h:104
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Definition: prioritybitmap.h:37
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...
Definition: prioritybitmap.h:52
RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor(unsigned int the_priority)
Definition: prioritybitmapimpl.h:128
const unsigned char _Bitfield_Leading_zeros[256]
Definition: log2table.c:24
Priority_bit_map_Word ready_major
Definition: prioritybitmap.h:63
Priority_bit_map_Word block_major
Definition: prioritybitmap.h:67
#define _CPU_Bitfield_Find_first_bit(_value, _output)
Definition: cpu.h:924
Priority_bit_map_Word block_minor
Definition: prioritybitmap.h:69
Priority_bit_map_Word * minor
Definition: prioritybitmap.h:61
RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add(Priority_bit_map_Control *bit_map, Priority_bit_map_Information *bit_map_info)
Definition: prioritybitmapimpl.h:144
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.
Definition: prioritybitmapimpl.h:55
Priority_bit_map_Word ready_minor
Definition: prioritybitmap.h:65
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...
Definition: prioritybitmap.h:42
Manipulation Routines for the Bitmap Priority Queue Implementation.
Definition: prioritybitmap.h:59
RTEMS_INLINE_ROUTINE unsigned int _Priority_Major(unsigned int the_priority)
Definition: prioritybitmapimpl.h:119
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.
Definition: prioritybitmapimpl.h:85
#define _CPU_Priority_Mask(_bit_number)
Definition: cpu.h:945