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 | |
---|
35 | struct _Scheduler_Control; |
---|
36 | |
---|
37 | #ifdef __cplusplus |
---|
38 | extern "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 Initializes a node. |
---|
55 | * |
---|
56 | * @param scheduler The scheduler for the initialization of @a node. |
---|
57 | * @param[out] node The node to initialize. |
---|
58 | * @param the_thread The thread for the initialization of @a node. |
---|
59 | * @param priority The priority value for @a node. |
---|
60 | */ |
---|
61 | RTEMS_INLINE_ROUTINE void _Scheduler_Node_do_initialize( |
---|
62 | const struct _Scheduler_Control *scheduler, |
---|
63 | Scheduler_Node *node, |
---|
64 | Thread_Control *the_thread, |
---|
65 | Priority_Control priority |
---|
66 | ) |
---|
67 | { |
---|
68 | node->owner = the_thread; |
---|
69 | |
---|
70 | node->Priority.value = priority; |
---|
71 | |
---|
72 | #if defined(RTEMS_SMP) |
---|
73 | _Chain_Initialize_node( &node->Thread.Wait_node ); |
---|
74 | node->Wait.Priority.scheduler = scheduler; |
---|
75 | node->user = the_thread; |
---|
76 | node->idle = NULL; |
---|
77 | _SMP_sequence_lock_Initialize( &node->Priority.Lock ); |
---|
78 | #else |
---|
79 | (void) scheduler; |
---|
80 | (void) the_thread; |
---|
81 | #endif |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * @brief Gets the scheduler of the node. |
---|
86 | * |
---|
87 | * @param node The node to get the scheduler of. |
---|
88 | * |
---|
89 | * @return The scheduler of the node. |
---|
90 | */ |
---|
91 | RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Node_get_scheduler( |
---|
92 | const Scheduler_Node *node |
---|
93 | ) |
---|
94 | { |
---|
95 | return _Priority_Get_scheduler( &node->Wait.Priority ); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * @brief Gets the owner of the node. |
---|
100 | * |
---|
101 | * @param node The node to get the owner of. |
---|
102 | * |
---|
103 | * @return The owner of the node. |
---|
104 | */ |
---|
105 | RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Node_get_owner( |
---|
106 | const Scheduler_Node *node |
---|
107 | ) |
---|
108 | { |
---|
109 | return node->owner; |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * @brief Gets the priority of the node. |
---|
114 | * |
---|
115 | * @param node The node to get the priority of. |
---|
116 | * |
---|
117 | * @return The priority of the node. |
---|
118 | */ |
---|
119 | RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Node_get_priority( |
---|
120 | Scheduler_Node *node |
---|
121 | ) |
---|
122 | { |
---|
123 | Priority_Control priority; |
---|
124 | |
---|
125 | #if defined(RTEMS_SMP) |
---|
126 | unsigned int seq; |
---|
127 | |
---|
128 | do { |
---|
129 | seq = _SMP_sequence_lock_Read_begin( &node->Priority.Lock ); |
---|
130 | #endif |
---|
131 | |
---|
132 | priority = node->Priority.value; |
---|
133 | |
---|
134 | #if defined(RTEMS_SMP) |
---|
135 | } while ( _SMP_sequence_lock_Read_retry( &node->Priority.Lock, seq ) ); |
---|
136 | #endif |
---|
137 | |
---|
138 | return priority; |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * @brief Sets the priority of the node. |
---|
143 | * |
---|
144 | * @param[in, out] node The node to set the priority of. |
---|
145 | * @param new_priority The new priority for @a node. |
---|
146 | * @param prepend_it Indicates whether the new priority should be prepended. |
---|
147 | */ |
---|
148 | RTEMS_INLINE_ROUTINE void _Scheduler_Node_set_priority( |
---|
149 | Scheduler_Node *node, |
---|
150 | Priority_Control new_priority, |
---|
151 | bool prepend_it |
---|
152 | ) |
---|
153 | { |
---|
154 | #if defined(RTEMS_SMP) |
---|
155 | unsigned int seq; |
---|
156 | |
---|
157 | seq = _SMP_sequence_lock_Write_begin( &node->Priority.Lock ); |
---|
158 | #endif |
---|
159 | |
---|
160 | new_priority |= ( prepend_it ? 0 : SCHEDULER_PRIORITY_APPEND_FLAG ); |
---|
161 | node->Priority.value = new_priority; |
---|
162 | |
---|
163 | #if defined(RTEMS_SMP) |
---|
164 | _SMP_sequence_lock_Write_end( &node->Priority.Lock, seq ); |
---|
165 | #endif |
---|
166 | } |
---|
167 | |
---|
168 | #if defined(RTEMS_SMP) |
---|
169 | /** |
---|
170 | * @brief Gets the user of the node. |
---|
171 | * |
---|
172 | * @param node The node to get the user of. |
---|
173 | * |
---|
174 | * @return The user of the node. |
---|
175 | */ |
---|
176 | RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Node_get_user( |
---|
177 | const Scheduler_Node *node |
---|
178 | ) |
---|
179 | { |
---|
180 | return node->user; |
---|
181 | } |
---|
182 | |
---|
183 | /** |
---|
184 | * @brief Sets the user of the node. |
---|
185 | * |
---|
186 | * @param[out] node The node to set the user of. |
---|
187 | * @param user The new user for @a node. |
---|
188 | */ |
---|
189 | RTEMS_INLINE_ROUTINE void _Scheduler_Node_set_user( |
---|
190 | Scheduler_Node *node, |
---|
191 | Thread_Control *user |
---|
192 | ) |
---|
193 | { |
---|
194 | node->user = user; |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | * @brief Gets the idle thread of the node. |
---|
199 | * |
---|
200 | * @param node The node to get the idle thread of. |
---|
201 | * |
---|
202 | * @return The idle thread of @a node. |
---|
203 | */ |
---|
204 | RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Node_get_idle( |
---|
205 | const Scheduler_Node *node |
---|
206 | ) |
---|
207 | { |
---|
208 | return node->idle; |
---|
209 | } |
---|
210 | #endif |
---|
211 | |
---|
212 | #ifdef __cplusplus |
---|
213 | } |
---|
214 | #endif /* __cplusplus */ |
---|
215 | |
---|
216 | /** @} */ |
---|
217 | |
---|
218 | #endif /* _RTEMS_SCORE_SCHEDULERNODEIMPL_H */ |
---|