source: rtems/cpukit/score/include/rtems/score/schedulerprioritysmpimpl.h @ 8f0c7a46

4.115
Last change on this file since 8f0c7a46 was 8f0c7a46, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/14 at 14:13:37

score: Decouple thread and scheduler nodes on SMP

Add a chain node to the scheduler node to decouple the thread and
scheduler nodes. It is now possible to enqueue a thread in a thread
wait queue and use its scheduler node at the same for other threads,
e.g. a resouce owner.

  • Property mode set to 100644
File size: 4.3 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_Node_get(
48  Thread_Control *thread
49)
50{
51  return (Scheduler_priority_SMP_Node *) _Scheduler_Node_get( 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 void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
61  Scheduler_Context *context,
62  Scheduler_Node    *scheduled_to_ready
63)
64{
65  Scheduler_priority_SMP_Context *self =
66    _Scheduler_priority_SMP_Get_self( context );
67  Scheduler_priority_SMP_Node *node =
68    _Scheduler_priority_SMP_Node_downcast( scheduled_to_ready );
69
70  _Chain_Extract_unprotected( &node->Base.Base.Node );
71  _Scheduler_priority_Ready_queue_enqueue_first(
72    &node->Base.Base.Node,
73    &node->Ready_queue,
74    &self->Bit_map
75  );
76}
77
78static inline void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
79  Scheduler_Context *context,
80  Scheduler_Node    *ready_to_scheduled
81)
82{
83  Scheduler_priority_SMP_Context *self =
84    _Scheduler_priority_SMP_Get_self( context );
85  Scheduler_priority_SMP_Node *node =
86    _Scheduler_priority_SMP_Node_downcast( ready_to_scheduled );
87
88  _Scheduler_priority_Ready_queue_extract(
89    &node->Base.Base.Node,
90    &node->Ready_queue,
91    &self->Bit_map
92  );
93  _Chain_Insert_ordered_unprotected(
94    &self->Base.Scheduled,
95    &node->Base.Base.Node,
96    _Scheduler_SMP_Insert_priority_fifo_order
97  );
98}
99
100static inline void _Scheduler_priority_SMP_Insert_ready_lifo(
101  Scheduler_Context *context,
102  Scheduler_Node    *thread
103)
104{
105  Scheduler_priority_SMP_Context *self =
106    _Scheduler_priority_SMP_Get_self( context );
107  Scheduler_priority_SMP_Node *node =
108    _Scheduler_priority_SMP_Node_downcast( thread );
109
110  _Scheduler_priority_Ready_queue_enqueue(
111    &node->Base.Base.Node,
112    &node->Ready_queue,
113    &self->Bit_map
114  );
115}
116
117static inline void _Scheduler_priority_SMP_Insert_ready_fifo(
118  Scheduler_Context *context,
119  Scheduler_Node    *thread
120)
121{
122  Scheduler_priority_SMP_Context *self =
123    _Scheduler_priority_SMP_Get_self( context );
124  Scheduler_priority_SMP_Node *node =
125    _Scheduler_priority_SMP_Node_downcast( thread );
126
127  _Scheduler_priority_Ready_queue_enqueue_first(
128    &node->Base.Base.Node,
129    &node->Ready_queue,
130    &self->Bit_map
131  );
132}
133
134static inline void _Scheduler_priority_SMP_Extract_from_ready(
135  Scheduler_Context *context,
136  Scheduler_Node    *thread
137)
138{
139  Scheduler_priority_SMP_Context *self =
140    _Scheduler_priority_SMP_Get_self( context );
141  Scheduler_priority_SMP_Node *node =
142    _Scheduler_priority_SMP_Node_downcast( thread );
143
144  _Scheduler_priority_Ready_queue_extract(
145    &node->Base.Base.Node,
146    &node->Ready_queue,
147    &self->Bit_map
148  );
149}
150
151static inline void _Scheduler_priority_SMP_Do_update(
152  Scheduler_Context *context,
153  Scheduler_Node *node_to_update,
154  Priority_Control new_priority
155)
156{
157  Scheduler_priority_SMP_Context *self =
158    _Scheduler_priority_SMP_Get_self( context );
159  Scheduler_priority_SMP_Node *node =
160    _Scheduler_priority_SMP_Node_downcast( node_to_update );
161
162  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
163  _Scheduler_priority_Ready_queue_update(
164    &node->Ready_queue,
165    new_priority,
166    &self->Bit_map,
167    &self->Ready[ 0 ]
168  );
169}
170
171/** @} */
172
173#ifdef __cplusplus
174}
175#endif /* __cplusplus */
176
177#endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H */
Note: See TracBrowser for help on using the repository browser.