source: rtems/cpukit/score/include/rtems/score/schedulerprioritysmpimpl.h @ 0c286e3

5
Last change on this file since 0c286e3 was 0c286e3, checked in by Sebastian Huber <sebastian.huber@…>, on 10/25/17 at 14:00:17

score: _Chain_Insert_ordered_unprotected()

Change the chain order relation to use a directly specified left hand
side value. This is similar to _RBTree_Insert_inline() and helps the
compiler to better optimize the code.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSchedulerPrioritySMP
5 *
6 * @brief Deterministic Priority SMP Scheduler API
7 */
8
9/*
10 * Copyright (c) 2013-2014 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_SCHEDULERPRIORITYSMPIMPL_H
24#define _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
25
26#include <rtems/score/schedulerprioritysmp.h>
27#include <rtems/score/schedulerpriorityimpl.h>
28#include <rtems/score/schedulersimpleimpl.h>
29#include <rtems/score/schedulersmpimpl.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
35/**
36 * @ingroup ScoreSchedulerPrioritySMP
37 * @{
38 */
39
40static inline Scheduler_priority_SMP_Context *_Scheduler_priority_SMP_Get_self(
41  Scheduler_Context *context
42)
43{
44  return (Scheduler_priority_SMP_Context *) context;
45}
46
47static inline Scheduler_priority_SMP_Node *_Scheduler_priority_SMP_Thread_get_node(
48  Thread_Control *thread
49)
50{
51  return (Scheduler_priority_SMP_Node *) _Thread_Scheduler_get_home_node( thread );
52}
53
54static inline Scheduler_priority_SMP_Node *
55_Scheduler_priority_SMP_Node_downcast( Scheduler_Node *node )
56{
57  return (Scheduler_priority_SMP_Node *) node;
58}
59
60static inline bool _Scheduler_priority_SMP_Has_ready( Scheduler_Context *context )
61{
62  Scheduler_priority_SMP_Context *self =
63    _Scheduler_priority_SMP_Get_self( context );
64
65  return !_Priority_bit_map_Is_empty( &self->Bit_map );
66}
67
68static inline void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
69  Scheduler_Context *context,
70  Scheduler_Node    *scheduled_to_ready
71)
72{
73  Scheduler_priority_SMP_Context *self =
74    _Scheduler_priority_SMP_Get_self( context );
75  Scheduler_priority_SMP_Node *node =
76    _Scheduler_priority_SMP_Node_downcast( scheduled_to_ready );
77
78  _Chain_Extract_unprotected( &node->Base.Base.Node.Chain );
79  _Scheduler_priority_Ready_queue_enqueue_first(
80    &node->Base.Base.Node.Chain,
81    &node->Ready_queue,
82    &self->Bit_map
83  );
84}
85
86static inline void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
87  Scheduler_Context *context,
88  Scheduler_Node    *ready_to_scheduled
89)
90{
91  Scheduler_priority_SMP_Context *self;
92  Scheduler_priority_SMP_Node    *node;
93  Priority_Control                priority;
94
95  self = _Scheduler_priority_SMP_Get_self( context );
96  node = _Scheduler_priority_SMP_Node_downcast( ready_to_scheduled );
97
98  _Scheduler_priority_Ready_queue_extract(
99    &node->Base.Base.Node.Chain,
100    &node->Ready_queue,
101    &self->Bit_map
102  );
103  priority = node->Base.priority;
104  _Chain_Insert_ordered_unprotected(
105    &self->Base.Scheduled,
106    &node->Base.Base.Node.Chain,
107    &priority,
108    _Scheduler_SMP_Insert_priority_fifo_order
109  );
110}
111
112static inline void _Scheduler_priority_SMP_Insert_ready_lifo(
113  Scheduler_Context *context,
114  Scheduler_Node    *thread
115)
116{
117  Scheduler_priority_SMP_Context *self =
118    _Scheduler_priority_SMP_Get_self( context );
119  Scheduler_priority_SMP_Node *node =
120    _Scheduler_priority_SMP_Node_downcast( thread );
121
122  _Scheduler_priority_Ready_queue_enqueue(
123    &node->Base.Base.Node.Chain,
124    &node->Ready_queue,
125    &self->Bit_map
126  );
127}
128
129static inline void _Scheduler_priority_SMP_Insert_ready_fifo(
130  Scheduler_Context *context,
131  Scheduler_Node    *thread
132)
133{
134  Scheduler_priority_SMP_Context *self =
135    _Scheduler_priority_SMP_Get_self( context );
136  Scheduler_priority_SMP_Node *node =
137    _Scheduler_priority_SMP_Node_downcast( thread );
138
139  _Scheduler_priority_Ready_queue_enqueue_first(
140    &node->Base.Base.Node.Chain,
141    &node->Ready_queue,
142    &self->Bit_map
143  );
144}
145
146static inline void _Scheduler_priority_SMP_Extract_from_ready(
147  Scheduler_Context *context,
148  Scheduler_Node    *thread
149)
150{
151  Scheduler_priority_SMP_Context *self =
152    _Scheduler_priority_SMP_Get_self( context );
153  Scheduler_priority_SMP_Node *node =
154    _Scheduler_priority_SMP_Node_downcast( thread );
155
156  _Scheduler_priority_Ready_queue_extract(
157    &node->Base.Base.Node.Chain,
158    &node->Ready_queue,
159    &self->Bit_map
160  );
161}
162
163static inline void _Scheduler_priority_SMP_Do_update(
164  Scheduler_Context *context,
165  Scheduler_Node *node_to_update,
166  Priority_Control new_priority
167)
168{
169  Scheduler_priority_SMP_Context *self =
170    _Scheduler_priority_SMP_Get_self( context );
171  Scheduler_priority_SMP_Node *node =
172    _Scheduler_priority_SMP_Node_downcast( node_to_update );
173
174  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
175  _Scheduler_priority_Ready_queue_update(
176    &node->Ready_queue,
177    new_priority,
178    &self->Bit_map,
179    &self->Ready[ 0 ]
180  );
181}
182
183/** @} */
184
185#ifdef __cplusplus
186}
187#endif /* __cplusplus */
188
189#endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H */
Note: See TracBrowser for help on using the repository browser.