source: rtems/cpukit/score/inline/rtems/score/priority.inl @ 61d330f5

4.104.114.84.95
Last change on this file since 61d330f5 was 61d330f5, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/21/05 at 07:53:52

New header guards.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/**
2 *  @file  rtems/score/priority.inl
3 *
4 *  This file contains the static inline implementation of all inlined
5 *  routines in the Priority Handler.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2004.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#ifndef _RTEMS_SCORE_PRIORITY_INL
20#define _RTEMS_SCORE_PRIORITY_INL
21
22/**
23 *  @addtogroup ScorePriority
24 *  @{
25 */
26
27#include <rtems/score/bitfield.h>
28
29/**
30 *  This routine performs the initialization necessary for this handler.
31 */
32
33RTEMS_INLINE_ROUTINE void _Priority_Handler_initialization( void )
34{
35  uint32_t   index;
36
37  _Priority_Major_bit_map = 0;
38  for ( index=0 ; index <16 ; index++ )
39     _Priority_Bit_map[ index ] = 0;
40}
41
42/**
43 *  This function returns TRUE if the_priority if valid for a
44 *  user task, and FALSE otherwise.
45 */
46
47RTEMS_INLINE_ROUTINE boolean _Priority_Is_valid (
48  Priority_Control the_priority
49)
50{
51  /*
52   *  Since PRIORITY_MINIMUM is 0 and priorities are stored unsigned,
53   *  then checking for less than 0 is unnecessary.
54   */
55
56  return ( the_priority <= PRIORITY_MAXIMUM );
57}
58
59/**
60 *  This function returns the major portion of the_priority.
61 */
62
63RTEMS_INLINE_ROUTINE uint32_t   _Priority_Major (
64  Priority_Control the_priority
65)
66{
67  return ( the_priority / 16 );
68}
69
70/**
71 *  This function returns the minor portion of the_priority.
72 */
73
74RTEMS_INLINE_ROUTINE uint32_t   _Priority_Minor (
75  Priority_Control the_priority
76)
77{
78  return ( the_priority % 16 );
79}
80
81#if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE )
82 
83/**
84 *  This function returns the mask associated with the major or minor
85 *  number passed to it.
86 */
87 
88RTEMS_INLINE_ROUTINE uint32_t   _Priority_Mask (
89  uint32_t   bit_number
90)
91{
92  return (0x8000 >> bit_number);
93}
94 
95 
96/**
97 *  This function translates the bit numbers returned by the bit scan
98 *  of a priority bit field into something suitable for use as
99 *  a major or minor component of a priority.
100 */
101 
102RTEMS_INLINE_ROUTINE uint32_t   _Priority_Bits_index (
103  uint32_t   bit_number
104)
105{
106  return bit_number;
107}
108
109#endif
110
111/**
112 *  This routine uses the_priority_map to update the priority
113 *  bit maps to indicate that a thread has been readied.
114 */
115
116RTEMS_INLINE_ROUTINE void _Priority_Add_to_bit_map (
117  Priority_Information *the_priority_map
118)
119{
120  *the_priority_map->minor |= the_priority_map->ready_minor;
121  _Priority_Major_bit_map  |= the_priority_map->ready_major;
122}
123
124/**
125 *  This routine uses the_priority_map to update the priority
126 *  bit maps to indicate that a thread has been removed from the
127 *  ready state.
128 */
129
130RTEMS_INLINE_ROUTINE void _Priority_Remove_from_bit_map (
131  Priority_Information *the_priority_map
132)
133{
134  *the_priority_map->minor &= the_priority_map->block_minor;
135  if ( *the_priority_map->minor == 0 )
136    _Priority_Major_bit_map &= the_priority_map->block_major;
137}
138
139/**
140 *  This function returns the priority of the highest priority
141 *  ready thread.
142 */
143
144RTEMS_INLINE_ROUTINE Priority_Control _Priority_Get_highest( void )
145{
146  Priority_Bit_map_control minor;
147  Priority_Bit_map_control major;
148
149  _Bitfield_Find_first_bit( _Priority_Major_bit_map, major );
150  _Bitfield_Find_first_bit( _Priority_Bit_map[major], minor );
151
152  return (_Priority_Bits_index( major ) << 4) +
153          _Priority_Bits_index( minor );
154}
155
156/**
157 *  This routine initializes the_priority_map so that it
158 *  contains the information necessary to manage a thread
159 *  at new_priority.
160 */
161
162RTEMS_INLINE_ROUTINE void _Priority_Initialize_information(
163  Priority_Information *the_priority_map,
164  Priority_Control      new_priority
165)
166{
167  Priority_Bit_map_control major;
168  Priority_Bit_map_control minor;
169  Priority_Bit_map_control mask;
170
171  major = _Priority_Major( new_priority );
172  minor = _Priority_Minor( new_priority );
173
174  the_priority_map->minor =
175    &_Priority_Bit_map[ _Priority_Bits_index(major) ];
176
177  mask = _Priority_Mask( major );
178  the_priority_map->ready_major = mask;
179  the_priority_map->block_major = ~mask;
180
181  mask = _Priority_Mask( minor );
182  the_priority_map->ready_minor = mask;
183  the_priority_map->block_minor = ~mask;
184}
185
186/**
187 *  This function returns TRUE if the priority GROUP is empty, and
188 *  FALSE otherwise.
189 */
190
191RTEMS_INLINE_ROUTINE boolean _Priority_Is_group_empty (
192  Priority_Control      the_priority
193)
194{
195  return the_priority == 0;
196}
197
198/**@}*/
199
200#endif
201/* end of include file */
Note: See TracBrowser for help on using the repository browser.