source: rtems/cpukit/score/include/rtems/score/prioritybitmapimpl.h @ b04b76c6

5
Last change on this file since b04b76c6 was b04b76c6, checked in by Sebastian Huber <sebastian.huber@…>, on 06/07/16 at 19:36:48

score: Simplify priority bit map implementation

The priority bit map can deal with a maximum of 256 priority values
ranging from 0 to 255. Consistently use an unsigned int for
computation, due to the usual integer promotion rules.

Make Priority_bit_map_Word definition architecture-independent and
define it to uint16_t. This was already the case for all architectures
except PowerPC. Adjust the PowerPC bitmap support accordingly.

  • Property mode set to 100644
File size: 6.1 KB
Line 
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
27extern "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 */
40extern 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#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
78/**
79 *  This method returns the priority bit mask for the specified major
80 *  or minor bit number.
81 *
82 *  @param[in] _bit_number is the bit number for which we need a mask
83 *
84 *  @retval the priority bit mask
85 *
86 *  @note This may simply be a pass through to a CPU dependent implementation.
87 */
88#define _Priority_Mask( _bit_number ) \
89  _CPU_Priority_Mask( _bit_number )
90#endif
91
92#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
93/**
94 *  This method returns the bit index position for the specified priority.
95 *
96 *  @param[in] _priority is the priority for which we need the index.
97 *
98 *  @retval This method returns the array index into the priority bit map.
99 *
100 *  @note This may simply be a pass through to a CPU dependent implementation.
101 */
102#define _Priority_Bits_index( _priority ) \
103  _CPU_Priority_bits_index( _priority )
104#endif
105
106/**
107 * This function returns the major portion of the_priority.
108 */
109
110RTEMS_INLINE_ROUTINE unsigned int _Priority_Major( unsigned int the_priority )
111{
112  return the_priority / 16;
113}
114
115/**
116 * This function returns the minor portion of the_priority.
117 */
118
119RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor( unsigned int the_priority )
120{
121  return the_priority % 16;
122}
123
124#if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE )
125
126/**
127 * This function returns the mask associated with the major or minor
128 * number passed to it.
129 */
130
131RTEMS_INLINE_ROUTINE Priority_bit_map_Word   _Priority_Mask (
132  unsigned int bit_number
133)
134{
135  return (Priority_bit_map_Word)(0x8000u >> bit_number);
136}
137
138/**
139 * This function translates the bit numbers returned by the bit scan
140 * of a priority bit field into something suitable for use as
141 * a major or minor component of a priority.
142 */
143
144RTEMS_INLINE_ROUTINE unsigned int _Priority_Bits_index(
145  unsigned int bit_number
146)
147{
148  return bit_number;
149}
150
151#endif
152
153RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize(
154  Priority_bit_map_Control *bit_map
155)
156{
157  memset( bit_map, 0, sizeof( *bit_map ) );
158}
159
160/**
161 * Priority Queue implemented by bit map
162 */
163
164RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add (
165  Priority_bit_map_Control     *bit_map,
166  Priority_bit_map_Information *bit_map_info
167)
168{
169  *bit_map_info->minor |= bit_map_info->ready_minor;
170  bit_map->major_bit_map |= bit_map_info->ready_major;
171}
172
173RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove (
174  Priority_bit_map_Control     *bit_map,
175  Priority_bit_map_Information *bit_map_info
176)
177{
178  *bit_map_info->minor &= bit_map_info->block_minor;
179  if ( *bit_map_info->minor == 0 )
180    bit_map->major_bit_map &= bit_map_info->block_major;
181}
182
183RTEMS_INLINE_ROUTINE unsigned int _Priority_bit_map_Get_highest(
184  const Priority_bit_map_Control *bit_map
185)
186{
187  unsigned int minor;
188  unsigned int major;
189
190  /* Avoid problems with some inline ASM statements */
191  unsigned int tmp;
192
193  tmp = bit_map->major_bit_map;
194  _Bitfield_Find_first_bit( tmp, major );
195
196  tmp = bit_map->bit_map[ major ];
197  _Bitfield_Find_first_bit( tmp, minor );
198
199  return (_Priority_Bits_index( major ) << 4) +
200          _Priority_Bits_index( minor );
201}
202
203RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty(
204  const Priority_bit_map_Control *bit_map
205)
206{
207  return bit_map->major_bit_map == 0;
208}
209
210RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(
211  Priority_bit_map_Control     *bit_map,
212  Priority_bit_map_Information *bit_map_info,
213  unsigned int                  new_priority
214)
215{
216  unsigned int major;
217  unsigned int minor;
218  Priority_bit_map_Word mask;
219
220  major = _Priority_Major( new_priority );
221  minor = _Priority_Minor( new_priority );
222
223  bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
224
225  mask = _Priority_Mask( major );
226  bit_map_info->ready_major = mask;
227  bit_map_info->block_major = (Priority_bit_map_Word) ~mask;
228
229  mask = _Priority_Mask( minor );
230  bit_map_info->ready_minor = mask;
231  bit_map_info->block_minor = (Priority_bit_map_Word) ~mask;
232}
233
234/** @} */
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif
241/* end of include file */
Note: See TracBrowser for help on using the repository browser.