source: rtems/cpukit/include/rtems/score/schedulerprioritysmpimpl.h @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreSchedulerPrioritySMP
7 *
8 * @brief This header file provides interfaces of the
9 *   @ref RTEMSScoreSchedulerPrioritySMP which are only used by the
10 *   implementation.
11 */
12
13/*
14 * Copyright (c) 2013, 2017 embedded brains GmbH.  All rights reserved.
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_SCHEDULERPRIORITYSMPIMPL_H
39#define _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
40
41#include <rtems/score/schedulerprioritysmp.h>
42#include <rtems/score/schedulerpriorityimpl.h>
43#include <rtems/score/schedulersimpleimpl.h>
44#include <rtems/score/schedulersmpimpl.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif /* __cplusplus */
49
50/**
51 * @ingroup RTEMSScoreSchedulerPrioritySMP
52 * @{
53 */
54
55static inline Scheduler_priority_SMP_Context *_Scheduler_priority_SMP_Get_self(
56  Scheduler_Context *context
57)
58{
59  return (Scheduler_priority_SMP_Context *) context;
60}
61
62static inline Scheduler_priority_SMP_Node *_Scheduler_priority_SMP_Thread_get_node(
63  Thread_Control *thread
64)
65{
66  return (Scheduler_priority_SMP_Node *) _Thread_Scheduler_get_home_node( thread );
67}
68
69static inline Scheduler_priority_SMP_Node *
70_Scheduler_priority_SMP_Node_downcast( Scheduler_Node *node )
71{
72  return (Scheduler_priority_SMP_Node *) node;
73}
74
75static inline bool _Scheduler_priority_SMP_Has_ready( Scheduler_Context *context )
76{
77  Scheduler_priority_SMP_Context *self =
78    _Scheduler_priority_SMP_Get_self( context );
79
80  return !_Priority_bit_map_Is_empty( &self->Bit_map );
81}
82
83static inline void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
84  Scheduler_Context *context,
85  Scheduler_Node    *scheduled_to_ready
86)
87{
88  Scheduler_priority_SMP_Context *self =
89    _Scheduler_priority_SMP_Get_self( context );
90  Scheduler_priority_SMP_Node *node =
91    _Scheduler_priority_SMP_Node_downcast( scheduled_to_ready );
92
93  _Chain_Extract_unprotected( &node->Base.Base.Node.Chain );
94  _Scheduler_priority_Ready_queue_enqueue_first(
95    &node->Base.Base.Node.Chain,
96    &node->Ready_queue,
97    &self->Bit_map
98  );
99}
100
101static inline void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
102  Scheduler_Context *context,
103  Scheduler_Node    *ready_to_scheduled
104)
105{
106  Scheduler_priority_SMP_Context *self;
107  Scheduler_priority_SMP_Node    *node;
108  Priority_Control                insert_priority;
109
110  self = _Scheduler_priority_SMP_Get_self( context );
111  node = _Scheduler_priority_SMP_Node_downcast( ready_to_scheduled );
112
113  _Scheduler_priority_Ready_queue_extract(
114    &node->Base.Base.Node.Chain,
115    &node->Ready_queue,
116    &self->Bit_map
117  );
118  insert_priority = _Scheduler_SMP_Node_priority( &node->Base.Base );
119  insert_priority = SCHEDULER_PRIORITY_APPEND( insert_priority );
120  _Chain_Insert_ordered_unprotected(
121    &self->Base.Scheduled,
122    &node->Base.Base.Node.Chain,
123    &insert_priority,
124    _Scheduler_SMP_Priority_less_equal
125  );
126}
127
128static inline void _Scheduler_priority_SMP_Insert_ready(
129  Scheduler_Context *context,
130  Scheduler_Node    *node_base,
131  Priority_Control   insert_priority
132)
133{
134  Scheduler_priority_SMP_Context *self;
135  Scheduler_priority_SMP_Node    *node;
136
137  self = _Scheduler_priority_SMP_Get_self( context );
138  node = _Scheduler_priority_SMP_Node_downcast( node_base );
139
140  if ( SCHEDULER_PRIORITY_IS_APPEND( insert_priority ) ) {
141    _Scheduler_priority_Ready_queue_enqueue(
142      &node->Base.Base.Node.Chain,
143      &node->Ready_queue,
144      &self->Bit_map
145    );
146  } else {
147    _Scheduler_priority_Ready_queue_enqueue_first(
148      &node->Base.Base.Node.Chain,
149      &node->Ready_queue,
150      &self->Bit_map
151    );
152  }
153}
154
155static inline void _Scheduler_priority_SMP_Extract_from_ready(
156  Scheduler_Context *context,
157  Scheduler_Node    *thread
158)
159{
160  Scheduler_priority_SMP_Context *self =
161    _Scheduler_priority_SMP_Get_self( context );
162  Scheduler_priority_SMP_Node *node =
163    _Scheduler_priority_SMP_Node_downcast( thread );
164
165  _Scheduler_priority_Ready_queue_extract(
166    &node->Base.Base.Node.Chain,
167    &node->Ready_queue,
168    &self->Bit_map
169  );
170}
171
172static inline Scheduler_Node *_Scheduler_priority_SMP_Get_idle( void *arg )
173{
174  Scheduler_priority_SMP_Context *self;
175  Scheduler_priority_SMP_Node    *lowest_ready;
176
177  self = _Scheduler_priority_SMP_Get_self( arg );
178  lowest_ready = (Scheduler_priority_SMP_Node *)
179    _Chain_Last( self->idle_ready_queue );
180  _Scheduler_priority_Ready_queue_extract(
181    &lowest_ready->Base.Base.Node.Chain,
182    &lowest_ready->Ready_queue,
183    &self->Bit_map
184  );
185
186  return &lowest_ready->Base.Base;
187}
188
189static inline void _Scheduler_priority_SMP_Release_idle(
190  Scheduler_Node *node_base,
191  void           *arg
192)
193{
194  Scheduler_priority_SMP_Context *self;
195  Scheduler_priority_SMP_Node    *node;
196
197  self = _Scheduler_priority_SMP_Get_self( arg );
198  node = _Scheduler_priority_SMP_Node_downcast( node_base );
199
200  _Scheduler_priority_Ready_queue_enqueue(
201    &node->Base.Base.Node.Chain,
202    &node->Ready_queue,
203    &self->Bit_map
204  );
205}
206
207static inline void _Scheduler_priority_SMP_Do_update(
208  Scheduler_Context *context,
209  Scheduler_Node    *node_to_update,
210  Priority_Control   new_priority
211)
212{
213  Scheduler_priority_SMP_Context *self;
214  Scheduler_priority_SMP_Node    *node;
215
216  self = _Scheduler_priority_SMP_Get_self( context );
217  node = _Scheduler_priority_SMP_Node_downcast( node_to_update );
218
219  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
220  _Scheduler_priority_Ready_queue_update(
221    &node->Ready_queue,
222    SCHEDULER_PRIORITY_UNMAP( new_priority ),
223    &self->Bit_map,
224    &self->Ready[ 0 ]
225  );
226}
227
228/** @} */
229
230#ifdef __cplusplus
231}
232#endif /* __cplusplus */
233
234#endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H */
Note: See TracBrowser for help on using the repository browser.