RTEMS CPU Kit with SuperCore  4.11.2
prioritybitmapimpl.h
Go to the documentation of this file.
1 
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 
23 #include <rtems/score/priority.h>
24 
25 #include <string.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
36 #if ( CPU_USE_GENERIC_BITFIELD_DATA == TRUE )
37 
43 extern const unsigned char __log2table[256];
44 
45 #endif
46 
66 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
67 #define _Bitfield_Find_first_bit( _value, _bit_number ) \
68  _CPU_Bitfield_Find_first_bit( _value, _bit_number )
69 #else
70 #define _Bitfield_Find_first_bit( _value, _bit_number ) \
71  { \
72  register uint32_t __value = (uint32_t) (_value); \
73  register const unsigned char *__p = __log2table; \
74  \
75  if ( __value < 0x100 ) \
76  (_bit_number) = (Priority_bit_map_Word)( __p[ __value ] + 8 ); \
77  else \
78  (_bit_number) = (Priority_bit_map_Word)( __p[ __value >> 8 ] ); \
79  }
80 #endif
81 
82 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
83 
93 #define _Priority_Mask( _bit_number ) \
94  _CPU_Priority_Mask( _bit_number )
95 #endif
96 
97 #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
98 
107 #define _Priority_Bits_index( _priority ) \
108  _CPU_Priority_bits_index( _priority )
109 #endif
110 
115 RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Major (
116  Priority_Control the_priority
117 )
118 {
119  return (Priority_bit_map_Word)( the_priority / 16 );
120 }
121 
126 RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Minor (
127  Priority_Control the_priority
128 )
129 {
130  return (Priority_bit_map_Word)( the_priority % 16 );
131 }
132 
133 #if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE )
134 
140 RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask (
141  uint32_t bit_number
142 )
143 {
144  return (Priority_bit_map_Word)(0x8000u >> bit_number);
145 }
146 
152  uint32_t mask
153 )
154 {
155  return (Priority_bit_map_Word)(~mask);
156 }
157 
165  uint32_t bit_number
166 )
167 {
168  return bit_number;
169 }
170 
171 #endif
172 
173 RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize(
174  Priority_bit_map_Control *bit_map
175 )
176 {
177  memset( bit_map, 0, sizeof( *bit_map ) );
178 }
179 
185  Priority_bit_map_Control *bit_map,
186  Priority_bit_map_Information *bit_map_info
187 )
188 {
189  *bit_map_info->minor |= bit_map_info->ready_minor;
190  bit_map->major_bit_map |= bit_map_info->ready_major;
191 }
192 
193 RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove (
194  Priority_bit_map_Control *bit_map,
195  Priority_bit_map_Information *bit_map_info
196 )
197 {
198  *bit_map_info->minor &= bit_map_info->block_minor;
199  if ( *bit_map_info->minor == 0 )
200  bit_map->major_bit_map &= bit_map_info->block_major;
201 }
202 
203 RTEMS_INLINE_ROUTINE Priority_Control _Priority_bit_map_Get_highest(
204  const Priority_bit_map_Control *bit_map
205 )
206 {
207  Priority_bit_map_Word minor;
208  Priority_bit_map_Word major;
209 
210  /* Avoid problems with some inline ASM statements */
211  Priority_bit_map_Word tmp;
212 
213  tmp = bit_map->major_bit_map;
214  _Bitfield_Find_first_bit( tmp, major );
215 
216  tmp = bit_map->bit_map[ major ];
217  _Bitfield_Find_first_bit( tmp, minor );
218 
219  return (_Priority_Bits_index( major ) << 4) +
220  _Priority_Bits_index( minor );
221 }
222 
223 RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty(
224  const Priority_bit_map_Control *bit_map
225 )
226 {
227  return bit_map->major_bit_map == 0;
228 }
229 
230 RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(
231  Priority_bit_map_Control *bit_map,
232  Priority_bit_map_Information *bit_map_info,
233  Priority_Control new_priority
234 )
235 {
236  Priority_bit_map_Word major;
237  Priority_bit_map_Word minor;
238  Priority_bit_map_Word mask;
239 
240  major = _Priority_Major( new_priority );
241  minor = _Priority_Minor( new_priority );
242 
243  bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
244 
245  mask = _Priority_Mask( major );
246  bit_map_info->ready_major = mask;
247  /* Add _Priority_Mask_invert to non-generic bitfield then change this code. */
248  bit_map_info->block_major = (Priority_bit_map_Word)(~((uint32_t)mask));
249 
250  mask = _Priority_Mask( minor );
251  bit_map_info->ready_minor = mask;
252  /* Add _Priority_Mask_invert to non-generic bitfield then change this code. */
253  bit_map_info->block_minor = (Priority_bit_map_Word)(~((uint32_t)mask));
254 }
255 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif
263 /* end of include file */
Thread Priority Manipulation Routines.
const unsigned char __log2table[256]
This table is used by the generic bitfield routines to perform a highly optimized bit scan without th...
Definition: log2table.c:25
#define _Priority_Bits_index(_priority)
This method returns the bit index position for the specified priority.
Definition: prioritybitmapimpl.h:107
#define _Bitfield_Find_first_bit(_value, _bit_number)
Gets the _bit_number of the first bit set in the specified value.
Definition: prioritybitmapimpl.h:67
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
Definition: prioritybitmap.h:40
Priority_bit_map_Word bit_map[16]
Each bit in the bit map indicates whether or not there are threads ready at a particular priority...
Definition: prioritybitmap.h:55
Priority_bit_map_Word ready_major
This is the priority bit map ready mask.
Definition: prioritybitmap.h:66
Priority_bit_map_Word block_major
This is the priority bit map block mask.
Definition: prioritybitmap.h:70
RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask_invert(uint32_t mask)
This function returns the mask bit inverted.
Definition: prioritybitmapimpl.h:151
uint32_t Priority_Control
The following type defines the control block used to manage thread priorities.
Definition: priority.h:56
RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Minor(Priority_Control the_priority)
This function returns the minor portion of the_priority.
Definition: prioritybitmapimpl.h:126
Priority_bit_map_Word block_minor
This is the priority bit map block mask.
Definition: prioritybitmap.h:72
Priority_bit_map_Word * minor
This is the address of minor bit map slot.
Definition: prioritybitmap.h:64
RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add(Priority_bit_map_Control *bit_map, Priority_bit_map_Information *bit_map_info)
Priority Queue implemented by bit map.
Definition: prioritybitmapimpl.h:184
Priority_bit_map_Word ready_minor
This is the priority bit map ready mask.
Definition: prioritybitmap.h:68
Priority_bit_map_Word major_bit_map
Each sixteen bit entry in this word is associated with one of the sixteen entries in the bit map...
Definition: prioritybitmap.h:45
Manipulation Routines for the Bitmap Priority Queue Implementation.
The following record defines the information associated with each thread to manage its interaction wi...
Definition: prioritybitmap.h:62
RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Major(Priority_Control the_priority)
This function returns the major portion of the_priority.
Definition: prioritybitmapimpl.h:115
#define _Priority_Mask(_bit_number)
This method returns the priority bit mask for the specified major or minor bit number.
Definition: prioritybitmapimpl.h:93