source: rtems/cpukit/include/rtems/score/schedulerprioritysmpimpl.h @ 7b85efb8

Last change on this file since 7b85efb8 was 7b85efb8, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 21:16:11

cpukit/include/rtems/score/[s-z]*.h: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 6.9 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 *  embedded brains GmbH
17 *  Dornierstr. 4
18 *  82178 Puchheim
19 *  Germany
20 *  <rtems@embedded-brains.de>
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the above copyright
26 *    notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 *    notice, this list of conditions and the following disclaimer in the
29 *    documentation and/or other materials provided with the distribution.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
42 */
43
44#ifndef _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
45#define _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
46
47#include <rtems/score/schedulerprioritysmp.h>
48#include <rtems/score/schedulerpriorityimpl.h>
49#include <rtems/score/schedulersimpleimpl.h>
50#include <rtems/score/schedulersmpimpl.h>
51
52#ifdef __cplusplus
53extern "C" {
54#endif /* __cplusplus */
55
56/**
57 * @ingroup RTEMSScoreSchedulerPrioritySMP
58 * @{
59 */
60
61static inline Scheduler_priority_SMP_Context *_Scheduler_priority_SMP_Get_self(
62  Scheduler_Context *context
63)
64{
65  return (Scheduler_priority_SMP_Context *) context;
66}
67
68static inline Scheduler_priority_SMP_Node *_Scheduler_priority_SMP_Thread_get_node(
69  Thread_Control *thread
70)
71{
72  return (Scheduler_priority_SMP_Node *) _Thread_Scheduler_get_home_node( thread );
73}
74
75static inline Scheduler_priority_SMP_Node *
76_Scheduler_priority_SMP_Node_downcast( Scheduler_Node *node )
77{
78  return (Scheduler_priority_SMP_Node *) node;
79}
80
81static inline bool _Scheduler_priority_SMP_Has_ready( Scheduler_Context *context )
82{
83  Scheduler_priority_SMP_Context *self =
84    _Scheduler_priority_SMP_Get_self( context );
85
86  return !_Priority_bit_map_Is_empty( &self->Bit_map );
87}
88
89static inline void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
90  Scheduler_Context *context,
91  Scheduler_Node    *scheduled_to_ready
92)
93{
94  Scheduler_priority_SMP_Context *self =
95    _Scheduler_priority_SMP_Get_self( context );
96  Scheduler_priority_SMP_Node *node =
97    _Scheduler_priority_SMP_Node_downcast( scheduled_to_ready );
98
99  _Chain_Extract_unprotected( &node->Base.Base.Node.Chain );
100  _Scheduler_priority_Ready_queue_enqueue_first(
101    &node->Base.Base.Node.Chain,
102    &node->Ready_queue,
103    &self->Bit_map
104  );
105}
106
107static inline void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
108  Scheduler_Context *context,
109  Scheduler_Node    *ready_to_scheduled
110)
111{
112  Scheduler_priority_SMP_Context *self;
113  Scheduler_priority_SMP_Node    *node;
114  Priority_Control                insert_priority;
115
116  self = _Scheduler_priority_SMP_Get_self( context );
117  node = _Scheduler_priority_SMP_Node_downcast( ready_to_scheduled );
118
119  _Scheduler_priority_Ready_queue_extract(
120    &node->Base.Base.Node.Chain,
121    &node->Ready_queue,
122    &self->Bit_map
123  );
124  insert_priority = _Scheduler_SMP_Node_priority( &node->Base.Base );
125  insert_priority = SCHEDULER_PRIORITY_APPEND( insert_priority );
126  _Chain_Insert_ordered_unprotected(
127    &self->Base.Scheduled,
128    &node->Base.Base.Node.Chain,
129    &insert_priority,
130    _Scheduler_SMP_Priority_less_equal
131  );
132}
133
134static inline void _Scheduler_priority_SMP_Insert_ready(
135  Scheduler_Context *context,
136  Scheduler_Node    *node_base,
137  Priority_Control   insert_priority
138)
139{
140  Scheduler_priority_SMP_Context *self;
141  Scheduler_priority_SMP_Node    *node;
142
143  self = _Scheduler_priority_SMP_Get_self( context );
144  node = _Scheduler_priority_SMP_Node_downcast( node_base );
145
146  if ( SCHEDULER_PRIORITY_IS_APPEND( insert_priority ) ) {
147    _Scheduler_priority_Ready_queue_enqueue(
148      &node->Base.Base.Node.Chain,
149      &node->Ready_queue,
150      &self->Bit_map
151    );
152  } else {
153    _Scheduler_priority_Ready_queue_enqueue_first(
154      &node->Base.Base.Node.Chain,
155      &node->Ready_queue,
156      &self->Bit_map
157    );
158  }
159}
160
161static inline void _Scheduler_priority_SMP_Extract_from_ready(
162  Scheduler_Context *context,
163  Scheduler_Node    *thread
164)
165{
166  Scheduler_priority_SMP_Context *self =
167    _Scheduler_priority_SMP_Get_self( context );
168  Scheduler_priority_SMP_Node *node =
169    _Scheduler_priority_SMP_Node_downcast( thread );
170
171  _Scheduler_priority_Ready_queue_extract(
172    &node->Base.Base.Node.Chain,
173    &node->Ready_queue,
174    &self->Bit_map
175  );
176}
177
178static inline Scheduler_Node *_Scheduler_priority_SMP_Get_idle( void *arg )
179{
180  Scheduler_priority_SMP_Context *self;
181  Scheduler_priority_SMP_Node    *lowest_ready;
182
183  self = _Scheduler_priority_SMP_Get_self( arg );
184  lowest_ready = (Scheduler_priority_SMP_Node *)
185    _Chain_Last( self->idle_ready_queue );
186  _Scheduler_priority_Ready_queue_extract(
187    &lowest_ready->Base.Base.Node.Chain,
188    &lowest_ready->Ready_queue,
189    &self->Bit_map
190  );
191
192  return &lowest_ready->Base.Base;
193}
194
195static inline void _Scheduler_priority_SMP_Release_idle(
196  Scheduler_Node *node_base,
197  void           *arg
198)
199{
200  Scheduler_priority_SMP_Context *self;
201  Scheduler_priority_SMP_Node    *node;
202
203  self = _Scheduler_priority_SMP_Get_self( arg );
204  node = _Scheduler_priority_SMP_Node_downcast( node_base );
205
206  _Scheduler_priority_Ready_queue_enqueue(
207    &node->Base.Base.Node.Chain,
208    &node->Ready_queue,
209    &self->Bit_map
210  );
211}
212
213static inline void _Scheduler_priority_SMP_Do_update(
214  Scheduler_Context *context,
215  Scheduler_Node    *node_to_update,
216  Priority_Control   new_priority
217)
218{
219  Scheduler_priority_SMP_Context *self;
220  Scheduler_priority_SMP_Node    *node;
221
222  self = _Scheduler_priority_SMP_Get_self( context );
223  node = _Scheduler_priority_SMP_Node_downcast( node_to_update );
224
225  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
226  _Scheduler_priority_Ready_queue_update(
227    &node->Ready_queue,
228    SCHEDULER_PRIORITY_UNMAP( new_priority ),
229    &self->Bit_map,
230    &self->Ready[ 0 ]
231  );
232}
233
234/** @} */
235
236#ifdef __cplusplus
237}
238#endif /* __cplusplus */
239
240#endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H */
Note: See TracBrowser for help on using the repository browser.