RTEMS 6.1-rc5
Loading...
Searching...
No Matches
schedulerpriorityimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
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
45#include <rtems/score/thread.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
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
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
91static inline Scheduler_priority_Node *_Scheduler_priority_Node_downcast(
92 Scheduler_Node *node
93)
94{
95 return (Scheduler_priority_Node *) node;
96}
97
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
127static inline void _Scheduler_priority_Ready_queue_enqueue(
128 Chain_Node *node,
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
148static inline void _Scheduler_priority_Ready_queue_enqueue_first(
149 Chain_Node *node,
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
167static inline void _Scheduler_priority_Ready_queue_extract(
168 Chain_Node *node,
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
191static inline void _Scheduler_priority_Extract_body(
192 const Scheduler_Control *scheduler,
193 Thread_Control *the_thread,
194 Scheduler_Node *node
195)
196{
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
220static inline Chain_Node *_Scheduler_priority_Ready_queue_first(
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
238static inline Thread_Control *_Scheduler_priority_Get_highest_ready(
239 const Scheduler_Control *scheduler
240)
241{
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
260static inline void _Scheduler_priority_Ready_queue_update(
262 unsigned int new_priority,
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
279#ifdef __cplusplus
280}
281#endif
282
283#endif
284/* end of include file */
This header file provides interfaces of the Chain Handler which are only used by the implementation.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:91
This header file provides interfaces of the Priority Bitmap which are only used by the implementation...
rtems_termios_device_context * context
Definition: console-config.c:62
This header file provides interfaces of the Deterministic Priority Scheduler which are used by the im...
This header file provides interfaces of the supporting the implementation of uniprocessor schedulers.
This header file provides interfaces of the Thread Handler which are used by the implementation and t...
This structure represents a chain node.
Definition: chain.h:78
Chain_Node Node
Definition: objectdata.h:63
Definition: prioritybitmap.h:60
Scheduler node for per-thread data.
Definition: schedulernode.h:94
Definition: schedulerpriority.h:83
Scheduler node specialization for Deterministic Priority schedulers.
Definition: schedulerpriority.h:119
Data for ready queue operations.
Definition: schedulerpriority.h:103
unsigned int current_priority
The thread priority currently used by the scheduler.
Definition: schedulerpriority.h:107
Chain_Control * ready_chain
Definition: schedulerpriority.h:110
Priority_bit_map_Information Priority_map
Definition: schedulerpriority.h:113
Scheduler control.
Definition: scheduler.h:337
Definition: thread.h:837
Objects_Control Object
Definition: thread.h:839
This union represents a chain control block.
Definition: chain.h:96