source: rtems/cpukit/score/include/rtems/score/prioritybitmapimpl.h @ 7103ad34

5
Last change on this file since 7103ad34 was 7103ad34, checked in by Sebastian Huber <sebastian.huber@…>, on 06/08/16 at 06:18:59

score: Define _Priority_Bits_index() once

  • Property mode set to 100644
File size: 5.6 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/**
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  /* Avoid problems with some inline ASM statements */
171  unsigned int tmp;
172
173  tmp = bit_map->major_bit_map;
174  _Bitfield_Find_first_bit( tmp, major );
175
176  tmp = bit_map->bit_map[ major ];
177  _Bitfield_Find_first_bit( tmp, minor );
178
179  return (_Priority_Bits_index( major ) << 4) +
180          _Priority_Bits_index( minor );
181}
182
183RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty(
184  const Priority_bit_map_Control *bit_map
185)
186{
187  return bit_map->major_bit_map == 0;
188}
189
190RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(
191  Priority_bit_map_Control     *bit_map,
192  Priority_bit_map_Information *bit_map_info,
193  unsigned int                  new_priority
194)
195{
196  unsigned int major;
197  unsigned int minor;
198  Priority_bit_map_Word mask;
199
200  major = _Priority_Major( new_priority );
201  minor = _Priority_Minor( new_priority );
202
203  bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
204
205  mask = _Priority_Mask( major );
206  bit_map_info->ready_major = mask;
207  bit_map_info->block_major = (Priority_bit_map_Word) ~mask;
208
209  mask = _Priority_Mask( minor );
210  bit_map_info->ready_minor = mask;
211  bit_map_info->block_minor = (Priority_bit_map_Word) ~mask;
212}
213
214/** @} */
215
216#ifdef __cplusplus
217}
218#endif
219
220#endif
221/* end of include file */
Note: See TracBrowser for help on using the repository browser.