source: rtems/cpukit/score/inline/rtems/score/priority.inl @ 4d03577

4.104.114.84.95
Last change on this file since 4d03577 was 4d03577, checked in by Ralf Corsepius <ralf.corsepius@…>, on 07/31/07 at 06:35:10

2007-07-31 Ralf Corsépius <ralf.corsepius@…>

  • score/inline/rtems/score/priority.inl: Use size_t instead of uint32_t for array index.
  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[baff4da]1/**
[11874561]2 *  @file  rtems/score/priority.inl
[ac7d5ef0]3 *
4 *  This file contains the static inline implementation of all inlined
5 *  routines in the Priority Handler.
[baff4da]6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2004.
[ac7d5ef0]10 *  On-Line Applications Research Corporation (OAR).
11 *
[98e4ebf5]12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[dd687d97]14 *  http://www.rtems.com/license/LICENSE.
[ac7d5ef0]15 *
16 *  $Id$
17 */
18
[61d330f5]19#ifndef _RTEMS_SCORE_PRIORITY_INL
20#define _RTEMS_SCORE_PRIORITY_INL
[ac7d5ef0]21
[baff4da]22/**
23 *  @addtogroup ScorePriority
24 *  @{
25 */
26
[5e9b32b]27#include <rtems/score/bitfield.h>
[ac7d5ef0]28
[baff4da]29/**
[1a8fde6c]30 *  This routine performs the initialization necessary for this handler.
[ac7d5ef0]31 */
32
[503dc058]33RTEMS_INLINE_ROUTINE void _Priority_Handler_initialization( void )
[ac7d5ef0]34{
[4d03577]35  size_t index;
[ac7d5ef0]36
37  _Priority_Major_bit_map = 0;
38  for ( index=0 ; index <16 ; index++ )
39     _Priority_Bit_map[ index ] = 0;
40}
41
[baff4da]42/**
[1a8fde6c]43 *  This function returns TRUE if the_priority if valid for a
44 *  user task, and FALSE otherwise.
[ac7d5ef0]45 */
46
[503dc058]47RTEMS_INLINE_ROUTINE boolean _Priority_Is_valid (
[7f6a24ab]48  Priority_Control the_priority
[ac7d5ef0]49)
50{
[3a4ae6c]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 );
[ac7d5ef0]57}
58
[baff4da]59/**
[1a8fde6c]60 *  This function returns the major portion of the_priority.
[ac7d5ef0]61 */
62
[d6154c7]63RTEMS_INLINE_ROUTINE uint32_t   _Priority_Major (
[7f6a24ab]64  Priority_Control the_priority
[ac7d5ef0]65)
66{
67  return ( the_priority / 16 );
68}
69
[baff4da]70/**
[1a8fde6c]71 *  This function returns the minor portion of the_priority.
[ac7d5ef0]72 */
73
[d6154c7]74RTEMS_INLINE_ROUTINE uint32_t   _Priority_Minor (
[7f6a24ab]75  Priority_Control the_priority
[ac7d5ef0]76)
77{
78  return ( the_priority % 16 );
79}
80
[9700578]81#if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE )
82 
[baff4da]83/**
[1a8fde6c]84 *  This function returns the mask associated with the major or minor
85 *  number passed to it.
[9700578]86 */
87 
[d6154c7]88RTEMS_INLINE_ROUTINE uint32_t   _Priority_Mask (
89  uint32_t   bit_number
[9700578]90)
91{
92  return (0x8000 >> bit_number);
93}
94 
95 
[baff4da]96/**
[1a8fde6c]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.
[9700578]100 */
101 
[d6154c7]102RTEMS_INLINE_ROUTINE uint32_t   _Priority_Bits_index (
103  uint32_t   bit_number
[9700578]104)
105{
106  return bit_number;
107}
108
109#endif
110
[baff4da]111/**
[1a8fde6c]112 *  This routine uses the_priority_map to update the priority
113 *  bit maps to indicate that a thread has been readied.
[ac7d5ef0]114 */
115
[503dc058]116RTEMS_INLINE_ROUTINE void _Priority_Add_to_bit_map (
[ac7d5ef0]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
[baff4da]124/**
[1a8fde6c]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.
[ac7d5ef0]128 */
129
[503dc058]130RTEMS_INLINE_ROUTINE void _Priority_Remove_from_bit_map (
[ac7d5ef0]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
[baff4da]139/**
[1a8fde6c]140 *  This function returns the priority of the highest priority
141 *  ready thread.
[ac7d5ef0]142 */
143
[503dc058]144RTEMS_INLINE_ROUTINE Priority_Control _Priority_Get_highest( void )
[ac7d5ef0]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
[9700578]152  return (_Priority_Bits_index( major ) << 4) +
153          _Priority_Bits_index( minor );
[ac7d5ef0]154}
155
[baff4da]156/**
[1a8fde6c]157 *  This routine initializes the_priority_map so that it
158 *  contains the information necessary to manage a thread
159 *  at new_priority.
[ac7d5ef0]160 */
161
[503dc058]162RTEMS_INLINE_ROUTINE void _Priority_Initialize_information(
[ac7d5ef0]163  Priority_Information *the_priority_map,
[7f6a24ab]164  Priority_Control      new_priority
[ac7d5ef0]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 =
[9700578]175    &_Priority_Bit_map[ _Priority_Bits_index(major) ];
[ac7d5ef0]176
[9700578]177  mask = _Priority_Mask( major );
[ac7d5ef0]178  the_priority_map->ready_major = mask;
179  the_priority_map->block_major = ~mask;
180
[9700578]181  mask = _Priority_Mask( minor );
[ac7d5ef0]182  the_priority_map->ready_minor = mask;
183  the_priority_map->block_minor = ~mask;
184}
185
[baff4da]186/**
[1a8fde6c]187 *  This function returns TRUE if the priority GROUP is empty, and
188 *  FALSE otherwise.
[ac7d5ef0]189 */
190
[503dc058]191RTEMS_INLINE_ROUTINE boolean _Priority_Is_group_empty (
[7f6a24ab]192  Priority_Control      the_priority
[ac7d5ef0]193)
194{
195  return the_priority == 0;
196}
197
[baff4da]198/**@}*/
199
[ac7d5ef0]200#endif
201/* end of include file */
Note: See TracBrowser for help on using the repository browser.