source: rtems/cpukit/include/rtems/score/schedulernodeimpl.h @ 5803f37

Last change on this file since 5803f37 was 5803f37, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 28, 2019 at 6:30:11 AM

score: Add and use _Thread_Get_unmapped_priority().

Add and use _Thread_Get_unmapped_real_priority().

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSScoreScheduler
5 *
6 * @brief Scheduler Node Implementation.
7 */
8
9/*
10 * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _RTEMS_SCORE_SCHEDULERNODEIMPL_H
24#define _RTEMS_SCORE_SCHEDULERNODEIMPL_H
25
26#include <rtems/score/schedulernode.h>
27#include <rtems/score/priorityimpl.h>
28
29/**
30 * @addtogroup RTEMSScoreScheduler
31 *
32 * @{
33 */
34
35struct _Scheduler_Control;
36
37#ifdef __cplusplus
38extern "C" {
39#endif /* __cplusplus */
40
41#define SCHEDULER_NODE_OF_WAIT_PRIORITY_NODE( node ) \
42  RTEMS_CONTAINER_OF( node, Scheduler_Node, Wait.Priority.Node.Node.Chain )
43
44#define SCHEDULER_NODE_OF_WAIT_PRIORITY( node ) \
45  RTEMS_CONTAINER_OF( node, Scheduler_Node, Wait.Priority )
46
47/**
48 * @brief Priority append indicator for the priority control used for the
49 * scheduler node priority.
50 */
51#define SCHEDULER_PRIORITY_APPEND_FLAG 1
52
53/**
54 * @brief Maps a priority value to support the append indicator.
55 */
56#define SCHEDULER_PRIORITY_MAP( priority ) ( ( priority ) << 1 )
57
58/**
59 * @brief Returns the plain priority value.
60 */
61#define SCHEDULER_PRIORITY_UNMAP( priority ) ( ( priority ) >> 1 )
62
63/**
64 * @brief Clears the priority append indicator bit.
65 */
66#define SCHEDULER_PRIORITY_PURIFY( priority )  \
67  ( ( priority ) & ~( (Priority_Control) SCHEDULER_PRIORITY_APPEND_FLAG ) )
68
69/**
70 * @brief Returns the priority control with the append indicator bit set.
71 */
72#define SCHEDULER_PRIORITY_APPEND( priority )  \
73  ( ( priority ) | SCHEDULER_PRIORITY_APPEND_FLAG )
74
75/**
76 * @brief Returns true, if the item should be appended to its priority group,
77 * otherwise returns false and the item should be prepended to its priority
78 * group.
79 */
80#define SCHEDULER_PRIORITY_IS_APPEND( priority ) \
81  ( ( ( priority ) & SCHEDULER_PRIORITY_APPEND_FLAG ) != 0 )
82
83/**
84 * @brief Initializes a node.
85 *
86 * @param scheduler The scheduler for the initialization of @a node.
87 * @param[out] node The node to initialize.
88 * @param the_thread The thread for the initialization of @a node.
89 * @param priority The priority value for @a node.
90 */
91RTEMS_INLINE_ROUTINE void _Scheduler_Node_do_initialize(
92  const struct _Scheduler_Control *scheduler,
93  Scheduler_Node                  *node,
94  Thread_Control                  *the_thread,
95  Priority_Control                 priority
96)
97{
98  node->owner = the_thread;
99
100  node->Priority.value = priority;
101
102#if defined(RTEMS_SMP)
103  _Chain_Initialize_node( &node->Thread.Wait_node );
104  node->Wait.Priority.scheduler = scheduler;
105  node->user = the_thread;
106  node->idle = NULL;
107  _SMP_sequence_lock_Initialize( &node->Priority.Lock );
108#else
109  (void) scheduler;
110  (void) the_thread;
111#endif
112}
113
114/**
115 * @brief Gets the scheduler of the node.
116 *
117 * @param node The node to get the scheduler of.
118 *
119 * @return The scheduler of the node.
120 */
121RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Node_get_scheduler(
122  const Scheduler_Node *node
123)
124{
125  return _Priority_Get_scheduler( &node->Wait.Priority );
126}
127
128/**
129 * @brief Gets the owner of the node.
130 *
131 * @param node The node to get the owner of.
132 *
133 * @return The owner of the node.
134 */
135RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Node_get_owner(
136  const Scheduler_Node *node
137)
138{
139  return node->owner;
140}
141
142/**
143 * @brief Gets the priority of the node.
144 *
145 * @param node The node to get the priority of.
146 *
147 * @return The priority of the node.
148 */
149RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Node_get_priority(
150  Scheduler_Node *node
151)
152{
153  Priority_Control priority;
154
155#if defined(RTEMS_SMP)
156  unsigned int     seq;
157
158  do {
159    seq = _SMP_sequence_lock_Read_begin( &node->Priority.Lock );
160#endif
161
162    priority = node->Priority.value;
163
164#if defined(RTEMS_SMP)
165  } while ( _SMP_sequence_lock_Read_retry( &node->Priority.Lock, seq ) );
166#endif
167
168  return priority;
169}
170
171/**
172 * @brief Sets the priority of the node.
173 *
174 * @param[in, out] node The node to set the priority of.
175 * @param new_priority The new priority for @a node.
176 * @param prepend_it Indicates whether the new priority should be prepended.
177 */
178RTEMS_INLINE_ROUTINE void _Scheduler_Node_set_priority(
179  Scheduler_Node   *node,
180  Priority_Control  new_priority,
181  bool              prepend_it
182)
183{
184#if defined(RTEMS_SMP)
185  unsigned int seq;
186
187  seq = _SMP_sequence_lock_Write_begin( &node->Priority.Lock );
188#endif
189
190  new_priority |= ( prepend_it ? 0 : SCHEDULER_PRIORITY_APPEND_FLAG );
191  node->Priority.value = new_priority;
192
193#if defined(RTEMS_SMP)
194  _SMP_sequence_lock_Write_end( &node->Priority.Lock, seq );
195#endif
196}
197
198#if defined(RTEMS_SMP)
199/**
200 * @brief Gets the user of the node.
201 *
202 * @param node The node to get the user of.
203 *
204 * @return The user of the node.
205 */
206RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Node_get_user(
207  const Scheduler_Node *node
208)
209{
210  return node->user;
211}
212
213/**
214 * @brief Sets the user of the node.
215 *
216 * @param[out] node The node to set the user of.
217 * @param user The new user for @a node.
218 */
219RTEMS_INLINE_ROUTINE void _Scheduler_Node_set_user(
220  Scheduler_Node *node,
221  Thread_Control *user
222)
223{
224  node->user = user;
225}
226
227/**
228 * @brief Gets the idle thread of the node.
229 *
230 * @param node The node to get the idle thread of.
231 *
232 * @return The idle thread of @a node.
233 */
234RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Node_get_idle(
235  const Scheduler_Node *node
236)
237{
238  return node->idle;
239}
240#endif
241
242#ifdef __cplusplus
243}
244#endif /* __cplusplus */
245
246/** @} */
247
248#endif /* _RTEMS_SCORE_SCHEDULERNODEIMPL_H */
Note: See TracBrowser for help on using the repository browser.