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

Last change on this file since a660e9dc was a660e9dc, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/22 at 08:37:05

Do not use RTEMS_INLINE_ROUTINE

Directly use "static inline" which is available in C99 and later. This brings
the RTEMS implementation closer to standard C.

Close #3935.

  • Property mode set to 100644
File size: 8.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreSchedulerDPS
7 *
8 * @brief This header file provides interfaces of the
9 *   @ref RTEMSScoreSchedulerDPS which are only used by the implementation.
10 */
11
12/*
13 *  Copyright (C) 2010 Gedare Bloom.
14 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_SCHEDULERPRIORITYIMPL_H
39#define _RTEMS_SCORE_SCHEDULERPRIORITYIMPL_H
40
41#include <rtems/score/schedulerpriority.h>
42#include <rtems/score/chainimpl.h>
43#include <rtems/score/prioritybitmapimpl.h>
44#include <rtems/score/scheduleruniimpl.h>
45#include <rtems/score/thread.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * @addtogroup RTEMSScoreSchedulerDPS
53 *
54 * @{
55 */
56
57/**
58 * @brief Gets the context of the scheduler.
59 *
60 * @param scheduler The scheduler to get the context of.
61 *
62 * @return The context of the scheduler.
63 */
64static inline Scheduler_priority_Context *
65  _Scheduler_priority_Get_context( const Scheduler_Control *scheduler )
66{
67  return (Scheduler_priority_Context *) _Scheduler_Get_context( scheduler );
68}
69
70/**
71 * @brief Gets the scheduler node of the thread.
72 *
73 * @param the_thread The thread to get the scheduler node of.
74 *
75 * @return The scheduler node of @a the_thread.
76 */
77static inline Scheduler_priority_Node *_Scheduler_priority_Thread_get_node(
78  Thread_Control *the_thread
79)
80{
81  return (Scheduler_priority_Node *) _Thread_Scheduler_get_home_node( the_thread );
82}
83
84/**
85 * @brief Gets the priority node of the scheduler node.
86 *
87 * @param node The node to get the priority node of.
88 *
89 * @return The priority node.
90 */
91static inline Scheduler_priority_Node *_Scheduler_priority_Node_downcast(
92  Scheduler_Node *node
93)
94{
95  return (Scheduler_priority_Node *) node;
96}
97
98/**
99 * @brief Ready queue initialization.
100 *
101 * This routine initializes @a ready_queues for priority-based scheduling.
102 *
103 * @param[out] ready_queues The ready queue to initialize.
104 * @param maximum_priority The maximum priority in the ready queue.
105 */
106static inline void _Scheduler_priority_Ready_queue_initialize(
107  Chain_Control    *ready_queues,
108  Priority_Control  maximum_priority
109)
110{
111  size_t index;
112
113  for ( index = 0 ; index <= (size_t) maximum_priority ; ++index ) {
114    _Chain_Initialize_empty( &ready_queues[ index ] );
115  }
116}
117
118/**
119 * @brief Enqueues a node on the specified ready queue.
120 *
121 * The node is placed as the last element of its priority group.
122 *
123 * @param node The node to enqueue.
124 * @param[in, out] ready_queue The ready queue.
125 * @param[out] bit_map The priority bit map of the scheduler instance.
126 */
127static inline void _Scheduler_priority_Ready_queue_enqueue(
128  Chain_Node                     *node,
129  Scheduler_priority_Ready_queue *ready_queue,
130  Priority_bit_map_Control       *bit_map
131)
132{
133  Chain_Control *ready_chain = ready_queue->ready_chain;
134
135  _Chain_Append_unprotected( ready_chain, node );
136  _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map );
137}
138
139/**
140 * @brief Enqueues a node on the specified ready queue as first.
141 *
142 * The node is placed as the first element of its priority group.
143 *
144 * @param node The node to enqueue as first.
145 * @param[in, out] ready_queue The ready queue.
146 * @param[out] bit_map The priority bit map of the scheduler instance.
147 */
148static inline void _Scheduler_priority_Ready_queue_enqueue_first(
149  Chain_Node                     *node,
150  Scheduler_priority_Ready_queue *ready_queue,
151  Priority_bit_map_Control       *bit_map
152)
153{
154  Chain_Control *ready_chain = ready_queue->ready_chain;
155
156  _Chain_Prepend_unprotected( ready_chain, node );
157  _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map );
158}
159
160/**
161 * @brief Extracts a node from the specified ready queue.
162 *
163 * @param node The node to extract.
164 * @param[in, out] ready_queue The ready queue.
165 * @param[out] bit_map The priority bit map of the scheduler instance.
166 */
167static inline void _Scheduler_priority_Ready_queue_extract(
168  Chain_Node                     *node,
169  Scheduler_priority_Ready_queue *ready_queue,
170  Priority_bit_map_Control       *bit_map
171)
172{
173  Chain_Control *ready_chain = ready_queue->ready_chain;
174
175  if ( _Chain_Has_only_one_node( ready_chain ) ) {
176    _Chain_Initialize_empty( ready_chain );
177    _Chain_Initialize_node( node );
178    _Priority_bit_map_Remove( bit_map, &ready_queue->Priority_map );
179  } else {
180    _Chain_Extract_unprotected( node );
181  }
182}
183
184/**
185 * @brief Extracts a node from the context of the scheduler.
186 *
187 * @param scheduler The scheduler instance.
188 * @param the_thread The thread of which the node will be extracted.
189 * @param[in, out] The node which preserves the ready queue.
190 */
191static inline void _Scheduler_priority_Extract_body(
192  const Scheduler_Control *scheduler,
193  Thread_Control          *the_thread,
194  Scheduler_Node          *node
195)
196{
197  Scheduler_priority_Context *context;
198  Scheduler_priority_Node    *the_node;
199
200  context = _Scheduler_priority_Get_context( scheduler );
201  the_node = _Scheduler_priority_Node_downcast( node );
202
203  _Scheduler_priority_Ready_queue_extract(
204    &the_thread->Object.Node,
205    &the_node->Ready_queue,
206    &context->Bit_map
207  );
208}
209
210/**
211 * @brief Returns a pointer to the first node.
212 *
213 * This routines returns a pointer to the first node on @a ready_queues.
214 *
215 * @param bit_map The priority bit map of the scheduler instance.
216 * @param ready_queues The ready queues of the scheduler instance.
217 *
218 * @return This method returns the first node.
219 */
220static inline Chain_Node *_Scheduler_priority_Ready_queue_first(
221  Priority_bit_map_Control *bit_map,
222  Chain_Control            *ready_queues
223)
224{
225  Priority_Control index = _Priority_bit_map_Get_highest( bit_map );
226  Chain_Node *first = _Chain_First( &ready_queues[ index ] );
227
228  _Assert( first != _Chain_Tail( &ready_queues[ index ] ) );
229
230  return first;
231}
232
233/**
234 * @brief Gets the highest priority ready thread of the scheduler.
235 *
236 * @param scheduler is the scheduler.
237 */
238static inline Thread_Control *_Scheduler_priority_Get_highest_ready(
239  const Scheduler_Control *scheduler
240)
241{
242  Scheduler_priority_Context *context =
243    _Scheduler_priority_Get_context( scheduler );
244
245  return (Thread_Control *) _Scheduler_priority_Ready_queue_first(
246    &context->Bit_map,
247    &context->Ready[ 0 ]
248  );
249}
250
251/**
252 * @brief Updates the specified ready queue data according to the new priority
253 * value.
254 *
255 * @param[in, out] ready_queue The ready queue.
256 * @param new_priority The new priority.
257 * @param bit_map The priority bit map of the scheduler instance.
258 * @param ready_queues The ready queues of the scheduler instance.
259 */
260static inline void _Scheduler_priority_Ready_queue_update(
261  Scheduler_priority_Ready_queue *ready_queue,
262  unsigned int                    new_priority,
263  Priority_bit_map_Control       *bit_map,
264  Chain_Control                  *ready_queues
265)
266{
267  ready_queue->current_priority = new_priority;
268  ready_queue->ready_chain = &ready_queues[ new_priority ];
269
270  _Priority_bit_map_Initialize_information(
271    bit_map,
272    &ready_queue->Priority_map,
273    new_priority
274  );
275}
276
277/** @} */
278
279#ifdef __cplusplus
280}
281#endif
282
283#endif
284/* end of include file */
Note: See TracBrowser for help on using the repository browser.