RTEMS
schedulernodeimpl.h
Go to the documentation of this file.
1 
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 
28 
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 
51 #define SCHEDULER_PRIORITY_APPEND_FLAG 1
52 
56 #define SCHEDULER_PRIORITY_MAP( priority ) ( ( priority ) << 1 )
57 
61 #define SCHEDULER_PRIORITY_UNMAP( priority ) ( ( priority ) >> 1 )
62 
66 #define SCHEDULER_PRIORITY_PURIFY( priority ) \
67  ( ( priority ) & ~( (Priority_Control) SCHEDULER_PRIORITY_APPEND_FLAG ) )
68 
72 #define SCHEDULER_PRIORITY_APPEND( priority ) \
73  ( ( priority ) | SCHEDULER_PRIORITY_APPEND_FLAG )
74 
80 #define SCHEDULER_PRIORITY_IS_APPEND( priority ) \
81  ( ( ( priority ) & SCHEDULER_PRIORITY_APPEND_FLAG ) != 0 )
82 
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)
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 
122  const Scheduler_Node *node
123 )
124 {
125  return _Priority_Get_scheduler( &node->Wait.Priority );
126 }
127 
136  const Scheduler_Node *node
137 )
138 {
139  return node->owner;
140 }
141 
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 
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 
207  const Scheduler_Node *node
208 )
209 {
210  return node->user;
211 }
212 
220  Scheduler_Node *node,
221  Thread_Control *user
222 )
223 {
224  node->user = user;
225 }
226 
235  const Scheduler_Node *node
236 )
237 {
238  return node->idle;
239 }
240 #endif
241 
242 #ifdef __cplusplus
243 }
244 #endif /* __cplusplus */
245 
248 #endif /* _RTEMS_SCORE_SCHEDULERNODEIMPL_H */
static void _SMP_sequence_lock_Initialize(SMP_sequence_lock_Control *lock)
Initializes an SMP sequence lock.
Definition: smplockseq.h:71
static unsigned int _SMP_sequence_lock_Write_begin(SMP_sequence_lock_Control *lock)
Begins an SMP sequence lock write operation.
Definition: smplockseq.h:99
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:70
static __inline__ const Scheduler_Control * _Priority_Get_scheduler(const Priority_Aggregation *aggregation)
Gets the priority aggregation&#39;s scheduler.
Definition: priorityimpl.h:284
const struct _Scheduler_Control * scheduler
The scheduler instance of this priority aggregation.
Definition: priority.h:159
static __inline__ void _Chain_Initialize_node(Chain_Node *the_node)
Initializes a chain node.
Definition: chainimpl.h:122
static __inline__ Priority_Control _Scheduler_Node_get_priority(Scheduler_Node *node)
Gets the priority of the node.
struct Scheduler_Node::@19 Thread
Block to register and manage this scheduler node in the thread control block of the owner of this sch...
static unsigned int _SMP_sequence_lock_Read_begin(const SMP_sequence_lock_Control *lock)
Begins an SMP sequence lock read operation.
Definition: smplockseq.h:139
struct _Thread_Control * idle
The idle thread claimed by this node in case the sticky level is greater than zero and the thread is ...
Chain_Node Wait_node
Node to add this scheduler node to Thread_Control::Scheduler::Wait_nodes.
struct _Thread_Control * user
The thread using this node.
static void _SMP_sequence_lock_Write_end(SMP_sequence_lock_Control *lock, unsigned int seq)
Ends an SMP sequence lock write operation.
Definition: smplockseq.h:122
static __inline__ Thread_Control * _Scheduler_Node_get_owner(const Scheduler_Node *node)
Gets the owner of the node.
static __inline__ void _Scheduler_Node_do_initialize(const struct _Scheduler_Control *scheduler, Scheduler_Node *node, Thread_Control *the_thread, Priority_Control priority)
Initializes a node.
static bool _SMP_sequence_lock_Read_retry(SMP_sequence_lock_Control *lock, unsigned int seq)
Ends an SMP sequence lock read operation and indicates if a retry is necessary.
Definition: smplockseq.h:157
#define SCHEDULER_PRIORITY_APPEND_FLAG
Priority append indicator for the priority control used for the scheduler node priority.
static __inline__ Thread_Control * _Scheduler_Node_get_idle(const Scheduler_Node *node)
Gets the idle thread of the node.
struct _Thread_Control * owner
The thread owning this node.
struct Scheduler_Node::@20 Wait
Thread wait support block.
static __inline__ void _Scheduler_Node_set_priority(Scheduler_Node *node, Priority_Control new_priority, bool prepend_it)
Sets the priority of the node.
Priority Handler API Implementation.
static __inline__ const Scheduler_Control * _Scheduler_Node_get_scheduler(const Scheduler_Node *node)
Gets the scheduler of the node.
Scheduler control.
Definition: scheduler.h:264
Scheduler node for per-thread data.
Definition: schedulernode.h:79
Handles Scheduler Nodes.
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
static __inline__ Thread_Control * _Scheduler_Node_get_user(const Scheduler_Node *node)
Gets the user of the node.
static __inline__ void _Scheduler_Node_set_user(Scheduler_Node *node, Thread_Control *user)
Sets the user of the node.