source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ 333f942

4.115
Last change on this file since 333f942 was 333f942, checked in by Sebastian Huber <sebastian.huber@…>, on 07/10/14 at 10:49:43

score: Fix assertions

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