source: rtems/cpukit/include/rtems/score/prioritybitmapimpl.h @ 5803f37

5
Last change on this file since 5803f37 was 536458a, checked in by Andreas Dachsberger <andreas.dachsberger@…>, on 04/10/19 at 09:05:31

doxygen: score: adjust doc in prioritybitmapimpl.h to doxygen guidelines

Update #3706.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSScorePriority
5 *
6 * @brief Inlined Routines in the Priority Handler Bit Map Implementation
7 *
8 * This file contains the static inline implementation of all inlined
9 * routines in the Priority Handler bit map implementation
10 */
11
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
24#include <rtems/score/prioritybitmap.h>
25
26#include <string.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * @addtogroup RTEMSScorePriority
34 *
35 * @{
36 */
37
38/**
39 *  This table is used by the generic bitfield routines to perform
40 *  a highly optimized bit scan without the use of special CPU
41 *  instructions.
42 */
43extern const unsigned char _Bitfield_Leading_zeros[256];
44
45/**
46 * @brief Returns the bit number of the first bit set in the specified value.
47 *
48 * The correspondence between the bit number and actual bit position is CPU
49 * architecture dependent.  The search for the first bit set may run from most
50 * to least significant bit or vice-versa.
51 *
52 * @param value The value to bit scan.
53 *
54 * @return The bit number of the first bit set.
55 *
56 * @see _Priority_Bits_index() and _Priority_Mask().
57 */
58RTEMS_INLINE_ROUTINE unsigned int _Bitfield_Find_first_bit(
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
80/**
81 * @brief Returns the priority bit mask for the specified major or minor bit
82 * number.
83 *
84 * @param bit_number The bit number for which we need a mask.
85 *
86 * @return The priority bit mask.
87 */
88RTEMS_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
99/**
100 * @brief Returns the bit index position for the specified major or minor bit
101 * number.
102 *
103 * @param bit_number The bit number for which we need an index.
104 *
105 * @return The corresponding array index into the priority bit map.
106 */
107RTEMS_INLINE_ROUTINE unsigned int _Priority_Bits_index(
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
118/**
119 * @brief Returns the major portion of the_priority.
120 *
121 * @param the_priority The priority of which we want the major portion.
122 *
123 * @return The major portion of the priority.
124 */
125RTEMS_INLINE_ROUTINE unsigned int _Priority_Major( unsigned int the_priority )
126{
127  return the_priority / 16;
128}
129
130/**
131 * @brief Returns the minor portion of the_priority.
132 *
133 * @param the_priority The priority of which we want the minor portion.
134 *
135 * @return The minor portion of the priority.
136 */
137RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor( unsigned int the_priority )
138{
139  return the_priority % 16;
140}
141
142/**
143 * @brief Initializes a bit map.
144 *
145 * @param[out] bit_map The bit map to initialize.
146 */
147RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize(
148  Priority_bit_map_Control *bit_map
149)
150{
151  memset( bit_map, 0, sizeof( *bit_map ) );
152}
153
154/**
155 * @brief Adds Priority queue bit map information.
156 *
157 * Priority Queue implemented by bit map.
158 *
159 * @param[out] bit_map The bit map to be altered by @a bit_map_info.
160 * @param bit_map_info The information with which to alter @a bit_map.
161 */
162RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add (
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
171/**
172 * @brief Removes Priority queue bit map information.
173 *
174 * Priority Queue implemented by bit map.
175 *
176 * @param[out] bit_map The bit map to be altered by @a bit_map_info.
177 * @param bit_map_info The information with which to alter @a bit_map.
178 */
179RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove (
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
189/**
190 * @brief Gets highest portion of Priority queue bit map.
191 *
192 * @param bit_map The bitmap to get the highest portion from.
193 *
194 * @return The highest portion of the bitmap.
195 */
196RTEMS_INLINE_ROUTINE unsigned int _Priority_bit_map_Get_highest(
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
210/**
211 * @brief Checks if the Priority queue bit map is empty.
212 *
213 * @param bit_map The bit map of which to check if it is empty.
214 *
215 * @retval true The Priority queue bit map is empty
216 * @retval false The Priority queue bit map is not empty.
217 */
218RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty(
219  const Priority_bit_map_Control *bit_map
220)
221{
222  return bit_map->major_bit_map == 0;
223}
224
225/**
226 * @brief Initializes the bit map information.
227 *
228 * @param bit_map The bit map for the initialization of the bit
229 *      map information.
230 * @param[out] bit_map_info The bit map information to initialize.
231 * @param new_priority The new priority for the initialization
232 *      of the bit map information.
233 */
234RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(
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
258/** @} */
259
260#ifdef __cplusplus
261}
262#endif
263
264#endif
265/* end of include file */
Note: See TracBrowser for help on using the repository browser.