File indexing completed on 2025-05-11 08:24:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef _RTEMS_SCORE_PRIORITYBITMAPIMPL_H
0039 #define _RTEMS_SCORE_PRIORITYBITMAPIMPL_H
0040
0041 #include <rtems/score/prioritybitmap.h>
0042
0043 #include <string.h>
0044
0045 #ifdef __cplusplus
0046 extern "C" {
0047 #endif
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 extern const unsigned char _Bitfield_Leading_zeros[256];
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 static inline unsigned int _Bitfield_Find_first_bit(
0076 unsigned int value
0077 )
0078 {
0079 unsigned int bit_number;
0080
0081 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
0082 _CPU_Bitfield_Find_first_bit( value, bit_number );
0083 #elif defined(__GNUC__)
0084 bit_number = (unsigned int) __builtin_clz( value )
0085 - __SIZEOF_INT__ * __CHAR_BIT__ + 16;
0086 #else
0087 if ( value < 0x100 ) {
0088 bit_number = _Bitfield_Leading_zeros[ value ] + 8;
0089 } else { \
0090 bit_number = _Bitfield_Leading_zeros[ value >> 8 ];
0091 }
0092 #endif
0093
0094 return bit_number;
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 static inline Priority_bit_map_Word _Priority_Mask(
0106 unsigned int bit_number
0107 )
0108 {
0109 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
0110 return _CPU_Priority_Mask( bit_number );
0111 #else
0112 return (Priority_bit_map_Word) ( 0x8000u >> bit_number );
0113 #endif
0114 }
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 static inline unsigned int _Priority_Bits_index(
0125 unsigned int bit_number
0126 )
0127 {
0128 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
0129 return _CPU_Priority_bits_index( bit_number );
0130 #else
0131 return bit_number;
0132 #endif
0133 }
0134
0135
0136
0137
0138
0139
0140
0141
0142 static inline unsigned int _Priority_Major( unsigned int the_priority )
0143 {
0144 return the_priority / 16;
0145 }
0146
0147
0148
0149
0150
0151
0152
0153
0154 static inline unsigned int _Priority_Minor( unsigned int the_priority )
0155 {
0156 return the_priority % 16;
0157 }
0158
0159
0160
0161
0162
0163
0164 static inline void _Priority_bit_map_Initialize(
0165 Priority_bit_map_Control *bit_map
0166 )
0167 {
0168 memset( bit_map, 0, sizeof( *bit_map ) );
0169 }
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 static inline void _Priority_bit_map_Add (
0180 Priority_bit_map_Control *bit_map,
0181 Priority_bit_map_Information *bit_map_info
0182 )
0183 {
0184 *bit_map_info->minor |= bit_map_info->ready_minor;
0185 bit_map->major_bit_map |= bit_map_info->ready_major;
0186 }
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 static inline void _Priority_bit_map_Remove (
0197 Priority_bit_map_Control *bit_map,
0198 Priority_bit_map_Information *bit_map_info
0199 )
0200 {
0201 *bit_map_info->minor &= bit_map_info->block_minor;
0202 if ( *bit_map_info->minor == 0 )
0203 bit_map->major_bit_map &= bit_map_info->block_major;
0204 }
0205
0206
0207
0208
0209
0210
0211
0212
0213 static inline unsigned int _Priority_bit_map_Get_highest(
0214 const Priority_bit_map_Control *bit_map
0215 )
0216 {
0217 unsigned int minor;
0218 unsigned int major;
0219
0220 major = _Bitfield_Find_first_bit( bit_map->major_bit_map );
0221 minor = _Bitfield_Find_first_bit( bit_map->bit_map[ major ] );
0222
0223 return (_Priority_Bits_index( major ) << 4) +
0224 _Priority_Bits_index( minor );
0225 }
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235 static inline bool _Priority_bit_map_Is_empty(
0236 const Priority_bit_map_Control *bit_map
0237 )
0238 {
0239 return bit_map->major_bit_map == 0;
0240 }
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 static inline void _Priority_bit_map_Initialize_information(
0252 Priority_bit_map_Control *bit_map,
0253 Priority_bit_map_Information *bit_map_info,
0254 unsigned int new_priority
0255 )
0256 {
0257 unsigned int major;
0258 unsigned int minor;
0259 Priority_bit_map_Word mask;
0260
0261 major = _Priority_Major( new_priority );
0262 minor = _Priority_Minor( new_priority );
0263
0264 bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
0265
0266 mask = _Priority_Mask( major );
0267 bit_map_info->ready_major = mask;
0268 bit_map_info->block_major = (Priority_bit_map_Word) ~mask;
0269
0270 mask = _Priority_Mask( minor );
0271 bit_map_info->ready_minor = mask;
0272 bit_map_info->block_minor = (Priority_bit_map_Word) ~mask;
0273 }
0274
0275
0276
0277 #ifdef __cplusplus
0278 }
0279 #endif
0280
0281 #endif
0282