RTEMS 6.1-rc5
Loading...
Searching...
No Matches
prioritybitmapimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2010.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_PRIORITYBITMAPIMPL_H
39#define _RTEMS_SCORE_PRIORITYBITMAPIMPL_H
40
42
43#include <string.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
60extern const unsigned char _Bitfield_Leading_zeros[256];
61
75static inline unsigned int _Bitfield_Find_first_bit(
76 unsigned int value
77)
78{
79 unsigned int bit_number;
80
81#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
82 _CPU_Bitfield_Find_first_bit( value, bit_number );
83#elif defined(__GNUC__)
84 bit_number = (unsigned int) __builtin_clz( value )
85 - __SIZEOF_INT__ * __CHAR_BIT__ + 16;
86#else
87 if ( value < 0x100 ) {
88 bit_number = _Bitfield_Leading_zeros[ value ] + 8;
89 } else { \
90 bit_number = _Bitfield_Leading_zeros[ value >> 8 ];
91 }
92#endif
93
94 return bit_number;
95}
96
105static inline Priority_bit_map_Word _Priority_Mask(
106 unsigned int bit_number
107)
108{
109#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
110 return _CPU_Priority_Mask( bit_number );
111#else
112 return (Priority_bit_map_Word) ( 0x8000u >> bit_number );
113#endif
114}
115
124static inline unsigned int _Priority_Bits_index(
125 unsigned int bit_number
126)
127{
128#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
129 return _CPU_Priority_bits_index( bit_number );
130#else
131 return bit_number;
132#endif
133}
134
142static inline unsigned int _Priority_Major( unsigned int the_priority )
143{
144 return the_priority / 16;
145}
146
154static inline unsigned int _Priority_Minor( unsigned int the_priority )
155{
156 return the_priority % 16;
157}
158
164static inline void _Priority_bit_map_Initialize(
166)
167{
168 memset( bit_map, 0, sizeof( *bit_map ) );
169}
170
179static inline void _Priority_bit_map_Add (
181 Priority_bit_map_Information *bit_map_info
182)
183{
184 *bit_map_info->minor |= bit_map_info->ready_minor;
185 bit_map->major_bit_map |= bit_map_info->ready_major;
186}
187
196static inline void _Priority_bit_map_Remove (
198 Priority_bit_map_Information *bit_map_info
199)
200{
201 *bit_map_info->minor &= bit_map_info->block_minor;
202 if ( *bit_map_info->minor == 0 )
203 bit_map->major_bit_map &= bit_map_info->block_major;
204}
205
213static inline unsigned int _Priority_bit_map_Get_highest(
214 const Priority_bit_map_Control *bit_map
215)
216{
217 unsigned int minor;
218 unsigned int major;
219
220 major = _Bitfield_Find_first_bit( bit_map->major_bit_map );
221 minor = _Bitfield_Find_first_bit( bit_map->bit_map[ major ] );
222
223 return (_Priority_Bits_index( major ) << 4) +
224 _Priority_Bits_index( minor );
225}
226
235static inline bool _Priority_bit_map_Is_empty(
236 const Priority_bit_map_Control *bit_map
237)
238{
239 return bit_map->major_bit_map == 0;
240}
241
251static inline void _Priority_bit_map_Initialize_information(
253 Priority_bit_map_Information *bit_map_info,
254 unsigned int new_priority
255)
256{
257 unsigned int major;
258 unsigned int minor;
259 Priority_bit_map_Word mask;
260
261 major = _Priority_Major( new_priority );
262 minor = _Priority_Minor( new_priority );
263
264 bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ];
265
266 mask = _Priority_Mask( major );
267 bit_map_info->ready_major = mask;
268 bit_map_info->block_major = (Priority_bit_map_Word) ~mask;
269
270 mask = _Priority_Mask( minor );
271 bit_map_info->ready_minor = mask;
272 bit_map_info->block_minor = (Priority_bit_map_Word) ~mask;
273}
274
277#ifdef __cplusplus
278}
279#endif
280
281#endif
282/* end of include file */
const unsigned char _Bitfield_Leading_zeros[256]
Definition: log2table.c:44
This header file provides interfaces of the Priority Bitmap which are used by the implementation and ...
Definition: prioritybitmap.h:60
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:65
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:75
Definition: prioritybitmap.h:82
Priority_bit_map_Word block_major
Definition: prioritybitmap.h:90
Priority_bit_map_Word block_minor
Definition: prioritybitmap.h:92
Priority_bit_map_Word ready_major
Definition: prioritybitmap.h:86
Priority_bit_map_Word ready_minor
Definition: prioritybitmap.h:88
Priority_bit_map_Word * minor
Definition: prioritybitmap.h:84