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

5
Last change on this file since b5f1b24 was 1d72f03, checked in by Sebastian Huber <sebastian.huber@…>, on 06/22/16 at 13:37:13

score: Silence integer conversion warnings

  • Property mode set to 100644
File size: 5.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 Returns the bit number of the first bit set in the specified value.
44 *
45 * The correspondence between the bit number and actual bit position is CPU
46 * architecture dependent.  The search for the first bit set may run from most
47 * to least significant bit or vice-versa.
48 *
49 * @param value The value to bit scan.
50 *
51 * @return The bit number of the first bit set.
52 *
53 * @see _Priority_Bits_index() and _Priority_Mask().
54 */
55RTEMS_INLINE_ROUTINE unsigned int _Bitfield_Find_first_bit(
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
77/**
78 * @brief Returns the priority bit mask for the specified major or minor bit
79 * number.
80 *
81 * @param bit_number The bit number for which we need a mask.
82 *
83 * @return The priority bit mask.
84 */
85RTEMS_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
96/**
97 * @brief Returns the bit index position for the specified major or minor bit
98 * number.
99 *
100 * @param bit_number The bit number for which we need an index.
101 *
102 * @return The corresponding array index into the priority bit map.
103 */
104RTEMS_INLINE_ROUTINE unsigned int _Priority_Bits_index(
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
115/**
116 * This function returns the major portion of the_priority.
117 */
118
119RTEMS_INLINE_ROUTINE unsigned int _Priority_Major( unsigned int the_priority )
120{
121  return the_priority / 16;
122}
123
124/**
125 * This function returns the minor portion of the_priority.
126 */
127
128RTEMS_INLINE_ROUTINE unsigned int _Priority_Minor( unsigned int the_priority )
129{
130  return the_priority % 16;
131}
132
133RTEMS_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
140/**
141 * Priority Queue implemented by bit map
142 */
143
144RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add (
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
153RTEMS_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
163RTEMS_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
177RTEMS_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
184RTEMS_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
208/** @} */
209
210#ifdef __cplusplus
211}
212#endif
213
214#endif
215/* end of include file */
Note: See TracBrowser for help on using the repository browser.