source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ 0c551f7

4.115
Last change on this file since 0c551f7 was 0c551f7, checked in by Sebastian Huber <sebastian.huber@…>, on 08/08/13 at 06:45:33

score: Add _Scheduler_priority_Get_scheduler_info

Add and use _Scheduler_priority_Get_scheduler_info().

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