source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ 2369b10

4.115
Last change on this file since 2369b10 was 2369b10, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/14 at 14:04:10

score: Add and use _Scheduler_Get_context()

  • Property mode set to 100644
File size: 6.9 KB
RevLine 
[d8134178]1/**
2 * @file
3 *
4 * @brief Inlined Routines Associated with the Manipulation of the
5 * Priority-Based Scheduling Structures
[0faa9dad]6 *
[d8134178]7 * This inline file contains all of the inlined routines associated with
8 * the manipulation of the priority-based scheduling structures.
[0faa9dad]9 */
10
11/*
12 *  Copyright (C) 2010 Gedare Bloom.
[010192d]13 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
[0faa9dad]14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
[c499856]17 *  http://www.rtems.org/license/LICENSE.
[0faa9dad]18 */
19
[f068384e]20#ifndef _RTEMS_SCORE_SCHEDULERPRIORITYIMPL_H
21#define _RTEMS_SCORE_SCHEDULERPRIORITYIMPL_H
[0faa9dad]22
[f068384e]23#include <rtems/score/schedulerpriority.h>
[6e93dc4a]24#include <rtems/score/chainimpl.h>
[f0bfd7d8]25#include <rtems/score/prioritybitmapimpl.h>
[e5ca54c9]26#include <rtems/score/schedulerimpl.h>
[a2e3f33]27#include <rtems/score/thread.h>
[108c4b0]28
[f068384e]29#ifdef __cplusplus
30extern "C" {
31#endif
32
[0faa9dad]33/**
[5b1ff71a]34 * @addtogroup ScoreSchedulerDPS
[0faa9dad]35 */
[b697bc6]36/**@{**/
[0faa9dad]37
[e1598a6]38RTEMS_INLINE_ROUTINE Scheduler_priority_Context *
39  _Scheduler_priority_Get_context( const Scheduler_Control *scheduler )
[f20b3d56]40{
[2369b10]41  return (Scheduler_priority_Context *) _Scheduler_Get_context( scheduler );
[f20b3d56]42}
43
[beab7329]44RTEMS_INLINE_ROUTINE Scheduler_priority_Node *_Scheduler_priority_Node_get(
45  Thread_Control *the_thread
46)
47{
48  return (Scheduler_priority_Node *) _Scheduler_Node_get( the_thread );
49}
50
[d8134178]51/**
52 * @brief Ready queue initialization.
[0faa9dad]53 *
[494c2e3]54 * This routine initializes @a ready_queues for priority-based scheduling.
[0faa9dad]55 */
[a78e575]56RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_initialize(
57  Chain_Control *ready_queues
58)
[010192d]59{
[a78e575]60  size_t index;
[0faa9dad]61
62  /* initialize ready queue structures */
63  for( index=0; index <= PRIORITY_MAXIMUM; index++)
[108c4b0]64    _Chain_Initialize_empty( &ready_queues[index] );
[0faa9dad]65}
66
[beab7329]67RTEMS_INLINE_ROUTINE Scheduler_priority_Node *
[0c551f7]68_Scheduler_priority_Get_scheduler_info( Thread_Control *thread )
69{
[beab7329]70  return ( Scheduler_priority_Node * ) thread->scheduler_node;
[0c551f7]71}
72
[010192d]73/**
[beab7329]74 * @brief Enqueues a thread on the specified ready queue.
[0faa9dad]75 *
[beab7329]76 * The thread is placed as the last element of its priority group.
[d8134178]77 *
[494c2e3]78 * @param[in] the_thread The thread to enqueue.
[beab7329]79 * @param[in] ready_queue The ready queue.
[494c2e3]80 * @param[in] bit_map The priority bit map of the scheduler instance.
[0faa9dad]81 */
82RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue(
[beab7329]83  Thread_Control                 *the_thread,
84  Scheduler_priority_Ready_queue *ready_queue,
85  Priority_bit_map_Control       *bit_map
[0faa9dad]86)
87{
[beab7329]88  Chain_Control *ready_chain = ready_queue->ready_chain;
[108c4b0]89
[0c551f7]90  _Chain_Append_unprotected( ready_chain, &the_thread->Object.Node );
[beab7329]91  _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map );
[0faa9dad]92}
93
[010192d]94/**
[beab7329]95 * @brief Enqueues a thread on the specified ready queue as first.
[0faa9dad]96 *
[beab7329]97 * The thread is placed as the first element of its priority group.
[d8134178]98 *
[beab7329]99 * @param[in] the_thread The thread to enqueue as first.
100 * @param[in] ready_queue The ready queue.
[494c2e3]101 * @param[in] bit_map The priority bit map of the scheduler instance.
[0faa9dad]102 */
103RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue_first(
[beab7329]104  Thread_Control                 *the_thread,
105  Scheduler_priority_Ready_queue *ready_queue,
106  Priority_bit_map_Control       *bit_map
[0faa9dad]107)
108{
[beab7329]109  Chain_Control *ready_chain = ready_queue->ready_chain;
[108c4b0]110
[0c551f7]111  _Chain_Prepend_unprotected( ready_chain, &the_thread->Object.Node );
[beab7329]112  _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map );
[0faa9dad]113}
114
[010192d]115/**
[beab7329]116 * @brief Extracts a thread from the specified ready queue.
[0faa9dad]117 *
[494c2e3]118 * @param[in] the_thread The thread to extract.
[beab7329]119 * @param[in] ready_queue The ready queue.
[494c2e3]120 * @param[in] bit_map The priority bit map of the scheduler instance.
[0faa9dad]121 */
122RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_extract(
[beab7329]123  Thread_Control                 *the_thread,
124  Scheduler_priority_Ready_queue *ready_queue,
125  Priority_bit_map_Control       *bit_map
[0faa9dad]126)
127{
[beab7329]128  Chain_Control *ready_chain = ready_queue->ready_chain;
[0faa9dad]129
[0c551f7]130  if ( _Chain_Has_only_one_node( ready_chain ) ) {
131    _Chain_Initialize_empty( ready_chain );
[beab7329]132    _Priority_bit_map_Remove( bit_map, &ready_queue->Priority_map );
[108c4b0]133  } else {
[0faa9dad]134    _Chain_Extract_unprotected( &the_thread->Object.Node );
[108c4b0]135  }
[0faa9dad]136}
137
[494c2e3]138RTEMS_INLINE_ROUTINE void _Scheduler_priority_Extract_body(
[e1598a6]139  const Scheduler_Control *scheduler,
140  Thread_Control          *the_thread
[494c2e3]141)
142{
[e1598a6]143  Scheduler_priority_Context *context =
144    _Scheduler_priority_Get_context( scheduler );
[beab7329]145  Scheduler_priority_Node *node = _Scheduler_priority_Node_get( the_thread );
[494c2e3]146
[beab7329]147  _Scheduler_priority_Ready_queue_extract(
148    the_thread,
149    &node->Ready_queue,
150    &context->Bit_map
151  );
[494c2e3]152}
153
[010192d]154/**
[d8134178]155 * @brief Return a pointer to the first thread.
[0faa9dad]156 *
[494c2e3]157 * This routines returns a pointer to the first thread on @a ready_queues.
[0faa9dad]158 *
[494c2e3]159 * @param[in] bit_map The priority bit map of the scheduler instance.
160 * @param[in] ready_queues The ready queues of the scheduler instance.
[0faa9dad]161 *
[d8134178]162 * @return This method returns the first thread or NULL
[0faa9dad]163 */
164RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_priority_Ready_queue_first(
[494c2e3]165  Priority_bit_map_Control *bit_map,
166  Chain_Control            *ready_queues
[0faa9dad]167)
168{
[494c2e3]169  Priority_Control index = _Priority_bit_map_Get_highest( bit_map );
[0faa9dad]170
[494c2e3]171  return (Thread_Control *) _Chain_First( &ready_queues[ index ] );
[0faa9dad]172}
173
[010192d]174/**
[d8134178]175 * @brief Scheduling decision logic.
[0faa9dad]176 *
[d8134178]177 * This kernel routine implements scheduling decision logic
178 * for priority-based scheduling.
[0faa9dad]179 */
[e5ca54c9]180RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body(
[e1598a6]181  const Scheduler_Control *scheduler,
182  Thread_Control          *the_thread,
183  bool                     force_dispatch
[e5ca54c9]184)
[0faa9dad]185{
[e1598a6]186  Scheduler_priority_Context *context =
187    _Scheduler_priority_Get_context( scheduler );
[494c2e3]188  Thread_Control *heir = _Scheduler_priority_Ready_queue_first(
[e1598a6]189    &context->Bit_map,
190    &context->Ready[ 0 ]
[494c2e3]191  );
[e5ca54c9]192
[24934e36]193  ( void ) the_thread;
[e5ca54c9]194
195  _Scheduler_Update_heir( heir, force_dispatch );
[0faa9dad]196}
197
[beab7329]198/**
199 * @brief Updates the specified ready queue data according to the current
200 * priority of the thread.
201 *
202 * @param[in] the_thread The thread.
203 * @param[in] ready_queue The ready queue.
204 * @param[in] bit_map The priority bit map of the scheduler instance.
205 * @param[in] ready_queues The ready queues of the scheduler instance.
206 */
207RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_update(
208  Thread_Control                 *the_thread,
209  Scheduler_priority_Ready_queue *ready_queue,
210  Priority_bit_map_Control       *bit_map,
211  Chain_Control                  *ready_queues
[99b3505]212)
213{
[beab7329]214  Priority_Control priority = the_thread->current_priority;
215  ready_queue->ready_chain = &ready_queues[ priority ];
[99b3505]216
217  _Priority_bit_map_Initialize_information(
[494c2e3]218    bit_map,
[beab7329]219    &ready_queue->Priority_map,
220    priority
[99b3505]221  );
222}
223
[ac9d2ecc]224/**
[d8134178]225 * @brief Priority comparison.
[ac9d2ecc]226 *
[d8134178]227 * This routine implements priority comparison for priority-based
228 * scheduling.
[ac9d2ecc]229 *
[d8134178]230 * @return >0 for higher priority, 0 for equal and <0 for lower priority.
[ac9d2ecc]231 */
232RTEMS_INLINE_ROUTINE int _Scheduler_priority_Priority_compare_body(
233  Priority_Control      p1,
234  Priority_Control      p2
235)
236{
237  /* High priority in priority scheduler is represented by low numbers. */
238  return ( p2 - p1 );
239}
240
[d8134178]241/** @} */
[0faa9dad]242
[f068384e]243#ifdef __cplusplus
244}
245#endif
246
[0faa9dad]247#endif
248/* end of include file */
Note: See TracBrowser for help on using the repository browser.