source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ e5ca54c9

4.115
Last change on this file since e5ca54c9 was e5ca54c9, checked in by Sebastian Huber <sebastian.huber@…>, on 08/07/13 at 19:19:55

score: PR2136: Fix _Thread_Change_priority()

Add call to _Scheduler_Schedule() in missing path after
_Thread_Set_transient() in _Thread_Change_priority(). See also
sptests/spintrcritical19.

Add thread parameter to _Scheduler_Schedule(). This parameter is
currently unused but may be used in future SMP schedulers.

Do heir selection in _Scheduler_Schedule(). Use
_Scheduler_Update_heir() for this in the particular scheduler
implementation.

Add and use _Scheduler_Generic_block().

  • Property mode set to 100644
File size: 5.7 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.com/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#include <rtems/score/wkspace.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 * @addtogroup ScoreScheduler
36 */
37/**@{**/
38
39/**
40 * @brief Ready queue initialization.
41 *
42 * This routine initializes @a the_ready_queue for priority-based scheduling.
43 */
44RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_initialize(void)
45{
46  size_t         index;
47  Chain_Control *ready_queues;
48
49  /* allocate ready queue structures */
50  _Scheduler.information = _Workspace_Allocate_or_fatal_error(
51    ((size_t) PRIORITY_MAXIMUM + 1) * sizeof(Chain_Control)
52  );
53
54  /* initialize ready queue structures */
55  ready_queues = (Chain_Control *) _Scheduler.information;
56  for( index=0; index <= PRIORITY_MAXIMUM; index++)
57    _Chain_Initialize_empty( &ready_queues[index] );
58}
59
60/**
61 * @brief Put a thread to the ready queue.
62 *
63 * This routine puts @a the_thread on to the priority-based ready queue.
64 *
65 * @param[in] the_thread is a pointer to the thread
66 */
67RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue(
68  Thread_Control                  *the_thread
69)
70{
71  Scheduler_priority_Per_thread *sched_info;
72  Chain_Control                 *ready;
73
74  sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
75  ready      = sched_info->ready_chain;
76
77  _Priority_bit_map_Add( &sched_info->Priority_map );
78
79  _Chain_Append_unprotected( ready, &the_thread->Object.Node );
80}
81
82/**
83 * @brief Put a thread to the head of the ready queue.
84 *
85 * This routine puts @a the_thread to the head of the ready queue.
86 * For priority-based ready queues, the thread will be the first thread
87 * at its priority level.
88 *
89 * @param[in] the_thread is a pointer to the thread.
90 */
91RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue_first(
92  Thread_Control                   *the_thread
93)
94{
95  Scheduler_priority_Per_thread *sched_info;
96
97  sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
98
99  _Priority_bit_map_Add( &sched_info->Priority_map );
100
101  _Chain_Prepend_unprotected(
102    sched_info->ready_chain,
103    &the_thread->Object.Node
104  );
105}
106
107/**
108 * @brief Remove a specific thread from the ready queue.
109 *
110 * This routine removes a specific thread from the specified
111 * priority-based ready queue.
112 *
113 * @param[in] the_thread is a pointer to the thread.
114 */
115RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_extract(
116  Thread_Control        *the_thread
117)
118{
119  Scheduler_priority_Per_thread *sched_info;
120  Chain_Control                 *ready;
121
122  sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
123  ready      = sched_info->ready_chain;
124
125  if ( _Chain_Has_only_one_node( ready ) ) {
126    _Chain_Initialize_empty( ready );
127    _Priority_bit_map_Remove( &sched_info->Priority_map );
128  } else {
129    _Chain_Extract_unprotected( &the_thread->Object.Node );
130  }
131}
132
133/**
134 * @brief Return a pointer to the first thread.
135 *
136 * This routines returns a pointer to the first thread on @a the_ready_queue.
137 *
138 * @param[in] the_ready_queue - pointer to thread queue
139 *
140 * @return This method returns the first thread or NULL
141 */
142RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_priority_Ready_queue_first(
143  Chain_Control       *the_ready_queue
144)
145{
146  Priority_Control index = _Priority_bit_map_Get_highest();
147
148  if ( !_Chain_Is_empty( &the_ready_queue[ index ] ) )
149    return (Thread_Control *) _Chain_First( &the_ready_queue[ index ] );
150
151  return NULL;
152}
153
154/**
155 * @brief Requeue a thread on the ready queue.
156 *
157 * This routine is invoked when a thread changes priority and should be
158 * moved to a different position on the ready queue.
159 *
160 * @param[in] the_thread is a pointer to the thread
161 */
162RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_requeue(
163  Thread_Control            *the_thread
164)
165{
166  Scheduler_priority_Per_thread *sched_info;
167
168  sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
169
170  if ( !_Chain_Has_only_one_node( sched_info->ready_chain ) ) {
171    _Chain_Extract_unprotected( &the_thread->Object.Node );
172
173    _Chain_Append_unprotected(
174      sched_info->ready_chain,
175      &the_thread->Object.Node
176    );
177  }
178}
179
180/**
181 * @brief Scheduling decision logic.
182 *
183 * This kernel routine implements scheduling decision logic
184 * for priority-based scheduling.
185 */
186RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body(
187  Thread_Control *thread,
188  bool force_dispatch
189)
190{
191  Thread_Control *heir = _Scheduler_priority_Ready_queue_first(
192    (Chain_Control *) _Scheduler.information
193  );
194
195  ( void ) thread;
196
197  _Scheduler_Update_heir( heir, force_dispatch );
198}
199
200/**
201 * @brief Priority comparison.
202 *
203 * This routine implements priority comparison for priority-based
204 * scheduling.
205 *
206 * @return >0 for higher priority, 0 for equal and <0 for lower priority.
207 */
208RTEMS_INLINE_ROUTINE int _Scheduler_priority_Priority_compare_body(
209  Priority_Control      p1,
210  Priority_Control      p2
211)
212{
213  /* High priority in priority scheduler is represented by low numbers. */
214  return ( p2 - p1 );
215}
216
217/** @} */
218
219#ifdef __cplusplus
220}
221#endif
222
223#endif
224/* end of include file */
Note: See TracBrowser for help on using the repository browser.