source: rtems/cpukit/score/src/schedulersimplesmp.c @ 8e467384

4.115
Last change on this file since 8e467384 was 8e467384, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 3, 2014 at 8:29:30 AM

score: Replace _Scheduler_Allocate/Free()

Replace _Scheduler_Allocate() with _Scheduler_Node_initialize(). Remove
the return status and thus the node initialization must be always
successful.

Rename _Scheduler_Free() to _Scheduler_Node_destroy().

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Simple SMP Scheduler Implementation
5 *
6 * @ingroup ScoreSchedulerSMPSimple
7 */
8
9/*
10 * Copyright (c) 2013-2014 embedded brains GmbH.
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include <rtems/score/schedulersimplesmp.h>
22#include <rtems/score/schedulersmpimpl.h>
23
24static Scheduler_simple_SMP_Context *
25_Scheduler_simple_SMP_Get_context( const Scheduler_Control *scheduler )
26{
27  return (Scheduler_simple_SMP_Context *) _Scheduler_Get_context( scheduler );
28}
29
30static Scheduler_simple_SMP_Context *
31_Scheduler_simple_SMP_Get_self( Scheduler_Context *context )
32{
33  return (Scheduler_simple_SMP_Context *) context;
34}
35
36void _Scheduler_simple_SMP_Initialize( const Scheduler_Control *scheduler )
37{
38  Scheduler_simple_SMP_Context *self =
39    _Scheduler_simple_SMP_Get_context( scheduler );
40
41  _Scheduler_SMP_Initialize( &self->Base );
42  _Chain_Initialize_empty( &self->Ready );
43}
44
45void _Scheduler_simple_SMP_Node_initialize(
46  const Scheduler_Control *scheduler,
47  Thread_Control          *the_thread
48)
49{
50  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( the_thread );
51
52  _Scheduler_SMP_Node_initialize( node );
53}
54
55static void _Scheduler_simple_SMP_Do_update(
56  Scheduler_Context *context,
57  Scheduler_Node *node,
58  Priority_Control new_priority
59)
60{
61  (void) context;
62  (void) node;
63  (void) new_priority;
64}
65
66static Thread_Control *_Scheduler_simple_SMP_Get_highest_ready(
67  Scheduler_Context *context
68)
69{
70  Scheduler_simple_SMP_Context *self =
71    _Scheduler_simple_SMP_Get_self( context );
72
73  return (Thread_Control *) _Chain_First( &self->Ready );
74}
75
76static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready(
77  Scheduler_Context *context,
78  Thread_Control *scheduled_to_ready
79)
80{
81  Scheduler_simple_SMP_Context *self =
82    _Scheduler_simple_SMP_Get_self( context );
83
84  _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node );
85  _Scheduler_simple_Insert_priority_lifo(
86    &self->Ready,
87    scheduled_to_ready
88  );
89}
90
91static void _Scheduler_simple_SMP_Move_from_ready_to_scheduled(
92  Scheduler_Context *context,
93  Thread_Control *ready_to_scheduled
94)
95{
96  Scheduler_simple_SMP_Context *self =
97    _Scheduler_simple_SMP_Get_self( context );
98
99  _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node );
100  _Scheduler_simple_Insert_priority_fifo(
101    &self->Base.Scheduled,
102    ready_to_scheduled
103  );
104}
105
106static void _Scheduler_simple_SMP_Insert_ready_lifo(
107  Scheduler_Context *context,
108  Thread_Control *thread
109)
110{
111  Scheduler_simple_SMP_Context *self =
112    _Scheduler_simple_SMP_Get_self( context );
113
114  _Chain_Insert_ordered_unprotected(
115    &self->Ready,
116    &thread->Object.Node,
117    _Scheduler_simple_Insert_priority_lifo_order
118  );
119}
120
121static void _Scheduler_simple_SMP_Insert_ready_fifo(
122  Scheduler_Context *context,
123  Thread_Control *thread
124)
125{
126  Scheduler_simple_SMP_Context *self =
127    _Scheduler_simple_SMP_Get_self( context );
128
129  _Chain_Insert_ordered_unprotected(
130    &self->Ready,
131    &thread->Object.Node,
132    _Scheduler_simple_Insert_priority_fifo_order
133  );
134}
135
136static void _Scheduler_simple_SMP_Extract_from_ready(
137  Scheduler_Context *context,
138  Thread_Control *thread
139)
140{
141  (void) context;
142
143  _Chain_Extract_unprotected( &thread->Object.Node );
144}
145
146void _Scheduler_simple_SMP_Block(
147  const Scheduler_Control *scheduler,
148  Thread_Control *thread
149)
150{
151  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
152
153  _Scheduler_SMP_Block(
154    context,
155    thread,
156    _Scheduler_simple_SMP_Extract_from_ready,
157    _Scheduler_simple_SMP_Get_highest_ready,
158    _Scheduler_simple_SMP_Move_from_ready_to_scheduled
159  );
160}
161
162static void _Scheduler_simple_SMP_Enqueue_ordered(
163  Scheduler_Context *context,
164  Thread_Control *thread,
165  Chain_Node_order order,
166  Scheduler_SMP_Insert insert_ready,
167  Scheduler_SMP_Insert insert_scheduled
168)
169{
170  _Scheduler_SMP_Enqueue_ordered(
171    context,
172    thread,
173    order,
174    insert_ready,
175    insert_scheduled,
176    _Scheduler_simple_SMP_Move_from_scheduled_to_ready
177  );
178}
179
180static void _Scheduler_simple_SMP_Enqueue_lifo(
181  Scheduler_Context *context,
182  Thread_Control *thread
183)
184{
185  _Scheduler_simple_SMP_Enqueue_ordered(
186    context,
187    thread,
188    _Scheduler_simple_Insert_priority_lifo_order,
189    _Scheduler_simple_SMP_Insert_ready_lifo,
190    _Scheduler_SMP_Insert_scheduled_lifo
191  );
192}
193
194static void _Scheduler_simple_SMP_Enqueue_fifo(
195  Scheduler_Context *context,
196  Thread_Control *thread
197)
198{
199  _Scheduler_simple_SMP_Enqueue_ordered(
200    context,
201    thread,
202    _Scheduler_simple_Insert_priority_fifo_order,
203    _Scheduler_simple_SMP_Insert_ready_fifo,
204    _Scheduler_SMP_Insert_scheduled_fifo
205  );
206}
207
208static void _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
209  Scheduler_Context *context,
210  Thread_Control *thread,
211  Chain_Node_order order,
212  Scheduler_SMP_Insert insert_ready,
213  Scheduler_SMP_Insert insert_scheduled
214)
215{
216  _Scheduler_SMP_Enqueue_scheduled_ordered(
217    context,
218    thread,
219    order,
220    _Scheduler_simple_SMP_Get_highest_ready,
221    insert_ready,
222    insert_scheduled,
223    _Scheduler_simple_SMP_Move_from_ready_to_scheduled
224  );
225}
226
227static void _Scheduler_simple_SMP_Enqueue_scheduled_lifo(
228  Scheduler_Context *context,
229  Thread_Control *thread
230)
231{
232  _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
233    context,
234    thread,
235    _Scheduler_simple_Insert_priority_lifo_order,
236    _Scheduler_simple_SMP_Insert_ready_lifo,
237    _Scheduler_SMP_Insert_scheduled_lifo
238  );
239}
240
241static void _Scheduler_simple_SMP_Enqueue_scheduled_fifo(
242  Scheduler_Context *context,
243  Thread_Control *thread
244)
245{
246  _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
247    context,
248    thread,
249    _Scheduler_simple_Insert_priority_fifo_order,
250    _Scheduler_simple_SMP_Insert_ready_fifo,
251    _Scheduler_SMP_Insert_scheduled_fifo
252  );
253}
254
255void _Scheduler_simple_SMP_Unblock(
256  const Scheduler_Control *scheduler,
257  Thread_Control *thread
258)
259{
260  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
261
262  _Scheduler_SMP_Unblock(
263    context,
264    thread,
265    _Scheduler_simple_SMP_Enqueue_fifo
266  );
267}
268
269void _Scheduler_simple_SMP_Change_priority(
270  const Scheduler_Control *scheduler,
271  Thread_Control          *thread,
272  Priority_Control         new_priority,
273  bool                     prepend_it
274)
275{
276  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
277
278  _Scheduler_SMP_Change_priority(
279    context,
280    thread,
281    new_priority,
282    prepend_it,
283    _Scheduler_simple_SMP_Extract_from_ready,
284    _Scheduler_simple_SMP_Do_update,
285    _Scheduler_simple_SMP_Enqueue_fifo,
286    _Scheduler_simple_SMP_Enqueue_lifo,
287    _Scheduler_simple_SMP_Enqueue_scheduled_fifo,
288    _Scheduler_simple_SMP_Enqueue_scheduled_lifo
289  );
290}
291
292void _Scheduler_simple_SMP_Yield(
293  const Scheduler_Control *scheduler,
294  Thread_Control *thread
295)
296{
297  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
298  ISR_Level level;
299
300  _ISR_Disable( level );
301
302  _Scheduler_SMP_Extract_from_scheduled( thread );
303  _Scheduler_simple_SMP_Enqueue_scheduled_fifo( context, thread );
304
305  _ISR_Enable( level );
306}
Note: See TracBrowser for help on using the repository browser.