RTEMS 6.1-rc1
scheduleredfimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copryight (c) 2011 Petr Benes.
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_SCHEDULEREDFIMPL_H
39#define _RTEMS_SCORE_SCHEDULEREDFIMPL_H
40
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
61#define SCHEDULER_EDF_PRIO_MSB 0x8000000000000000
62
70static inline Scheduler_EDF_Context *
71 _Scheduler_EDF_Get_context( const Scheduler_Control *scheduler )
72{
73 return (Scheduler_EDF_Context *) _Scheduler_Get_context( scheduler );
74}
75
83static inline Scheduler_EDF_Node *_Scheduler_EDF_Thread_get_node(
84 Thread_Control *the_thread
85)
86{
87 return (Scheduler_EDF_Node *) _Thread_Scheduler_get_home_node( the_thread );
88}
89
97static inline Scheduler_EDF_Node * _Scheduler_EDF_Node_downcast(
98 Scheduler_Node *node
99)
100{
101 return (Scheduler_EDF_Node *) node;
102}
103
113static inline bool _Scheduler_EDF_Less(
114 const void *left,
115 const RBTree_Node *right
116)
117{
118 const Priority_Control *the_left;
119 const Scheduler_EDF_Node *the_right;
120 Priority_Control prio_left;
121 Priority_Control prio_right;
122
123 the_left = (const Priority_Control *) left;
124 the_right = RTEMS_CONTAINER_OF( right, Scheduler_EDF_Node, Node );
125
126 prio_left = *the_left;
127 prio_right = the_right->priority;
128
129 return prio_left < prio_right;
130}
131
141static inline bool _Scheduler_EDF_Priority_less_equal(
142 const void *left,
143 const RBTree_Node *right
144)
145{
146 const Priority_Control *the_left;
147 const Scheduler_EDF_Node *the_right;
148 Priority_Control prio_left;
149 Priority_Control prio_right;
150
151 the_left = (const Priority_Control *) left;
152 the_right = RTEMS_CONTAINER_OF( right, Scheduler_EDF_Node, Node );
153
154 prio_left = *the_left;
155 prio_right = the_right->priority;
156
157 return prio_left <= prio_right;
158}
159
168static inline void _Scheduler_EDF_Enqueue(
170 Scheduler_EDF_Node *node,
171 Priority_Control insert_priority
172)
173{
174 _RBTree_Insert_inline(
175 &context->Ready,
176 &node->Node,
177 &insert_priority,
178 _Scheduler_EDF_Priority_less_equal
179 );
180}
181
188static inline void _Scheduler_EDF_Extract(
191)
192{
193 _RBTree_Extract( &context->Ready, &node->Node );
194}
195
203static inline void _Scheduler_EDF_Extract_body(
204 const Scheduler_Control *scheduler,
205 Thread_Control *the_thread,
206 Scheduler_Node *node
207)
208{
210 Scheduler_EDF_Node *the_node;
211
212 context = _Scheduler_EDF_Get_context( scheduler );
213 the_node = _Scheduler_EDF_Node_downcast( node );
214
215 _Scheduler_EDF_Extract( context, the_node );
216}
217
223static inline Thread_Control *_Scheduler_EDF_Get_highest_ready(
224 const Scheduler_Control *scheduler
225)
226{
228 RBTree_Node *first;
229 Scheduler_EDF_Node *node;
230
231 context = _Scheduler_EDF_Get_context( scheduler );
232 first = _RBTree_Minimum( &context->Ready );
233 node = RTEMS_CONTAINER_OF( first, Scheduler_EDF_Node, Node );
234
235 return node->Base.owner;
236}
237
240#ifdef __cplusplus
241}
242#endif
243
244#endif
245/* end of include file */
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Gets the container of a member.
Definition: basedefs.h:306
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:91
void _RBTree_Extract(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Extracts (removes) the node from the red-black tree.
Definition: rbtreeextract.c:63
RBTree_Node * _RBTree_Minimum(const RBTree_Control *the_rbtree)
Returns the minimum node of the red-black tree.
Definition: rbtreemin.c:43
rtems_termios_device_context * context
Definition: console-config.c:62
This header file provides interfaces of the EDF Scheduler which are used by the implementation and th...
This header file provides interfaces of the supporting the implementation of uniprocessor schedulers.
Red-black tree node.
Definition: rbtree.h:73
Definition: scheduleredf.h:92
Scheduler node specialization for EDF schedulers.
Definition: scheduleredf.h:107
Priority_Control priority
The thread priority currently used for this scheduler instance.
Definition: scheduleredf.h:121
Scheduler node for per-thread data.
Definition: schedulernode.h:94
Scheduler control.
Definition: scheduler.h:335
Definition: thread.h:812