source: rtems/cpukit/score/inline/rtems/score/priority.inl @ ef49476

4.104.114.95
Last change on this file since ef49476 was ef49476, checked in by Ralf Corsepius <ralf.corsepius@…>, on 08/19/08 at 08:32:59

Add header guard to force indirect inclusion.

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