source: rtems/cpukit/score/src/schedulerprioritysmp.c @ 99fc1d1d

5
Last change on this file since 99fc1d1d was 042072b, checked in by Sebastian Huber <sebastian.huber@…>, on 06/14/16 at 08:12:34

score: _Scheduler_priority_Ready_queue_initialize

Use priority maximum of scheduler instance. This avoids a potential
memory corruption on SMP configurations.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSchedulerPrioritySMP
5 *
6 * @brief Deterministic Priority SMP Scheduler Implementation
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#if HAVE_CONFIG_H
24  #include "config.h"
25#endif
26
27#include <rtems/score/schedulerprioritysmpimpl.h>
28
29static Scheduler_priority_SMP_Context *
30_Scheduler_priority_SMP_Get_context( const Scheduler_Control *scheduler )
31{
32  return (Scheduler_priority_SMP_Context *) _Scheduler_Get_context( scheduler );
33}
34
35void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler )
36{
37  Scheduler_priority_SMP_Context *self =
38    _Scheduler_priority_SMP_Get_context( scheduler );
39
40  _Scheduler_SMP_Initialize( &self->Base );
41  _Priority_bit_map_Initialize( &self->Bit_map );
42  _Scheduler_priority_Ready_queue_initialize(
43    &self->Ready[ 0 ],
44    scheduler->maximum_priority
45  );
46}
47
48void _Scheduler_priority_SMP_Node_initialize(
49  const Scheduler_Control *scheduler,
50  Thread_Control *thread
51)
52{
53  Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_own_node( thread );
54
55  _Scheduler_SMP_Node_initialize( node, thread );
56}
57
58void _Scheduler_priority_SMP_Update_priority(
59  const Scheduler_Control *scheduler,
60  Thread_Control *thread,
61  Priority_Control new_priority
62)
63{
64  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
65  Scheduler_Node *node = _Scheduler_Thread_get_node( thread );
66
67  _Scheduler_priority_SMP_Do_update( context, node, new_priority );
68}
69
70static Scheduler_Node *_Scheduler_priority_SMP_Get_highest_ready(
71  Scheduler_Context *context,
72  Scheduler_Node    *node
73)
74{
75  Scheduler_priority_SMP_Context *self =
76    _Scheduler_priority_SMP_Get_self( context );
77
78  (void) node;
79
80  return (Scheduler_Node *) _Scheduler_priority_Ready_queue_first(
81    &self->Bit_map,
82    &self->Ready[ 0 ]
83  );
84}
85
86void _Scheduler_priority_SMP_Block(
87  const Scheduler_Control *scheduler,
88  Thread_Control *thread
89)
90{
91  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
92
93  _Scheduler_SMP_Block(
94    context,
95    thread,
96    _Scheduler_priority_SMP_Extract_from_ready,
97    _Scheduler_priority_SMP_Get_highest_ready,
98    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
99    _Scheduler_SMP_Allocate_processor_lazy
100  );
101}
102
103static Thread_Control *_Scheduler_priority_SMP_Enqueue_ordered(
104  Scheduler_Context    *context,
105  Scheduler_Node       *node,
106  Thread_Control       *needs_help,
107  Chain_Node_order      order,
108  Scheduler_SMP_Insert  insert_ready,
109  Scheduler_SMP_Insert  insert_scheduled
110)
111{
112  return _Scheduler_SMP_Enqueue_ordered(
113    context,
114    node,
115    needs_help,
116    order,
117    insert_ready,
118    insert_scheduled,
119    _Scheduler_priority_SMP_Move_from_scheduled_to_ready,
120    _Scheduler_SMP_Get_lowest_scheduled,
121    _Scheduler_SMP_Allocate_processor_lazy
122  );
123}
124
125static Thread_Control *_Scheduler_priority_SMP_Enqueue_lifo(
126  Scheduler_Context *context,
127  Scheduler_Node    *node,
128  Thread_Control    *needs_help
129)
130{
131  return _Scheduler_priority_SMP_Enqueue_ordered(
132    context,
133    node,
134    needs_help,
135    _Scheduler_SMP_Insert_priority_lifo_order,
136    _Scheduler_priority_SMP_Insert_ready_lifo,
137    _Scheduler_SMP_Insert_scheduled_lifo
138  );
139}
140
141static Thread_Control *_Scheduler_priority_SMP_Enqueue_fifo(
142  Scheduler_Context *context,
143  Scheduler_Node    *node,
144  Thread_Control    *needs_help
145)
146{
147  return _Scheduler_priority_SMP_Enqueue_ordered(
148    context,
149    node,
150    needs_help,
151    _Scheduler_SMP_Insert_priority_fifo_order,
152    _Scheduler_priority_SMP_Insert_ready_fifo,
153    _Scheduler_SMP_Insert_scheduled_fifo
154  );
155}
156
157static Thread_Control *_Scheduler_priority_SMP_Enqueue_scheduled_ordered(
158  Scheduler_Context *context,
159  Scheduler_Node *node,
160  Chain_Node_order order,
161  Scheduler_SMP_Insert insert_ready,
162  Scheduler_SMP_Insert insert_scheduled
163)
164{
165  return _Scheduler_SMP_Enqueue_scheduled_ordered(
166    context,
167    node,
168    order,
169    _Scheduler_priority_SMP_Extract_from_ready,
170    _Scheduler_priority_SMP_Get_highest_ready,
171    insert_ready,
172    insert_scheduled,
173    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
174    _Scheduler_SMP_Allocate_processor_lazy
175  );
176}
177
178static Thread_Control *_Scheduler_priority_SMP_Enqueue_scheduled_lifo(
179  Scheduler_Context *context,
180  Scheduler_Node *node
181)
182{
183  return _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
184    context,
185    node,
186    _Scheduler_SMP_Insert_priority_lifo_order,
187    _Scheduler_priority_SMP_Insert_ready_lifo,
188    _Scheduler_SMP_Insert_scheduled_lifo
189  );
190}
191
192static Thread_Control *_Scheduler_priority_SMP_Enqueue_scheduled_fifo(
193  Scheduler_Context *context,
194  Scheduler_Node *node
195)
196{
197  return _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
198    context,
199    node,
200    _Scheduler_SMP_Insert_priority_fifo_order,
201    _Scheduler_priority_SMP_Insert_ready_fifo,
202    _Scheduler_SMP_Insert_scheduled_fifo
203  );
204}
205
206Thread_Control *_Scheduler_priority_SMP_Unblock(
207  const Scheduler_Control *scheduler,
208  Thread_Control *thread
209)
210{
211  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
212
213  return _Scheduler_SMP_Unblock(
214    context,
215    thread,
216    _Scheduler_priority_SMP_Enqueue_fifo
217  );
218}
219
220Thread_Control *_Scheduler_priority_SMP_Change_priority(
221  const Scheduler_Control *scheduler,
222  Thread_Control          *thread,
223  Priority_Control         new_priority,
224  bool                     prepend_it
225)
226{
227  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
228
229  return _Scheduler_SMP_Change_priority(
230    context,
231    thread,
232    new_priority,
233    prepend_it,
234    _Scheduler_priority_SMP_Extract_from_ready,
235    _Scheduler_priority_SMP_Do_update,
236    _Scheduler_priority_SMP_Enqueue_fifo,
237    _Scheduler_priority_SMP_Enqueue_lifo,
238    _Scheduler_priority_SMP_Enqueue_scheduled_fifo,
239    _Scheduler_priority_SMP_Enqueue_scheduled_lifo
240  );
241}
242
243Thread_Control *_Scheduler_priority_SMP_Ask_for_help(
244  const Scheduler_Control *scheduler,
245  Thread_Control          *offers_help,
246  Thread_Control          *needs_help
247)
248{
249  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
250
251  return _Scheduler_SMP_Ask_for_help(
252    context,
253    offers_help,
254    needs_help,
255    _Scheduler_priority_SMP_Enqueue_fifo
256  );
257}
258
259Thread_Control *_Scheduler_priority_SMP_Yield(
260  const Scheduler_Control *scheduler,
261  Thread_Control *thread
262)
263{
264  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
265
266  return _Scheduler_SMP_Yield(
267    context,
268    thread,
269    _Scheduler_priority_SMP_Extract_from_ready,
270    _Scheduler_priority_SMP_Enqueue_fifo,
271    _Scheduler_priority_SMP_Enqueue_scheduled_fifo
272  );
273}
Note: See TracBrowser for help on using the repository browser.