1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines Associated with the Manipulation of the Scheduler |
---|
5 | * |
---|
6 | * This inline file contains all of the inlined routines associated with |
---|
7 | * the manipulation of the scheduler. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * Copyright (C) 2010 Gedare Bloom. |
---|
12 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_SCHEDULERIMPL_H |
---|
20 | #define _RTEMS_SCORE_SCHEDULERIMPL_H |
---|
21 | |
---|
22 | #include <rtems/score/scheduler.h> |
---|
23 | #include <rtems/score/cpusetimpl.h> |
---|
24 | #include <rtems/score/smpimpl.h> |
---|
25 | #include <rtems/score/threadimpl.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @addtogroup ScoreScheduler |
---|
33 | */ |
---|
34 | /**@{**/ |
---|
35 | |
---|
36 | /** |
---|
37 | * @brief Initializes the scheduler to the policy chosen by the user. |
---|
38 | * |
---|
39 | * This routine initializes the scheduler to the policy chosen by the user |
---|
40 | * through confdefs, or to the priority scheduler with ready chains by |
---|
41 | * default. |
---|
42 | */ |
---|
43 | void _Scheduler_Handler_initialization( void ); |
---|
44 | |
---|
45 | RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_CPU_index( |
---|
46 | uint32_t cpu_index |
---|
47 | ) |
---|
48 | { |
---|
49 | #if defined(RTEMS_SMP) |
---|
50 | return _Scheduler_Assignments[ cpu_index ].scheduler; |
---|
51 | #else |
---|
52 | (void) cpu_index; |
---|
53 | |
---|
54 | return &_Scheduler_Table[ 0 ]; |
---|
55 | #endif |
---|
56 | } |
---|
57 | |
---|
58 | RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_CPU( |
---|
59 | const Per_CPU_Control *cpu |
---|
60 | ) |
---|
61 | { |
---|
62 | uint32_t cpu_index = _Per_CPU_Get_index( cpu ); |
---|
63 | |
---|
64 | return _Scheduler_Get_by_CPU_index( cpu_index ); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * The preferred method to add a new scheduler is to define the jump table |
---|
69 | * entries and add a case to the _Scheduler_Initialize routine. |
---|
70 | * |
---|
71 | * Generic scheduling implementations that rely on the ready queue only can |
---|
72 | * be found in the _Scheduler_queue_XXX functions. |
---|
73 | */ |
---|
74 | |
---|
75 | /* |
---|
76 | * Passing the Scheduler_Control* to these functions allows for multiple |
---|
77 | * scheduler's to exist simultaneously, which could be useful on an SMP |
---|
78 | * system. Then remote Schedulers may be accessible. How to protect such |
---|
79 | * accesses remains an open problem. |
---|
80 | */ |
---|
81 | |
---|
82 | /** |
---|
83 | * @brief Scheduler schedule. |
---|
84 | * |
---|
85 | * This kernel routine implements the scheduling decision logic for |
---|
86 | * the scheduler. It does NOT dispatch. |
---|
87 | * |
---|
88 | * @param[in] the_thread The thread which state changed previously. |
---|
89 | */ |
---|
90 | RTEMS_INLINE_ROUTINE void _Scheduler_Schedule( |
---|
91 | const Scheduler_Control *scheduler, |
---|
92 | Thread_Control *the_thread |
---|
93 | ) |
---|
94 | { |
---|
95 | ( *scheduler->Operations.schedule )( scheduler, the_thread ); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * @brief Scheduler yield with a particular thread. |
---|
100 | * |
---|
101 | * This routine is invoked when a thread wishes to voluntarily transfer control |
---|
102 | * of the processor to another thread. |
---|
103 | * |
---|
104 | * @param[in] the_thread The yielding thread. |
---|
105 | */ |
---|
106 | RTEMS_INLINE_ROUTINE void _Scheduler_Yield( |
---|
107 | const Scheduler_Control *scheduler, |
---|
108 | Thread_Control *the_thread |
---|
109 | ) |
---|
110 | { |
---|
111 | ( *scheduler->Operations.yield )( scheduler, the_thread ); |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * @brief Scheduler block. |
---|
116 | * |
---|
117 | * This routine removes @a the_thread from the scheduling decision for |
---|
118 | * the scheduler. The primary task is to remove the thread from the |
---|
119 | * ready queue. It performs any necessary schedulering operations |
---|
120 | * including the selection of a new heir thread. |
---|
121 | */ |
---|
122 | RTEMS_INLINE_ROUTINE void _Scheduler_Block( |
---|
123 | const Scheduler_Control *scheduler, |
---|
124 | Thread_Control *the_thread |
---|
125 | ) |
---|
126 | { |
---|
127 | ( *scheduler->Operations.block )( scheduler, the_thread ); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * @brief Scheduler unblock. |
---|
132 | * |
---|
133 | * This routine adds @a the_thread to the scheduling decision for |
---|
134 | * the scheduler. The primary task is to add the thread to the |
---|
135 | * ready queue per the schedulering policy and update any appropriate |
---|
136 | * scheduling variables, for example the heir thread. |
---|
137 | */ |
---|
138 | RTEMS_INLINE_ROUTINE void _Scheduler_Unblock( |
---|
139 | const Scheduler_Control *scheduler, |
---|
140 | Thread_Control *the_thread |
---|
141 | ) |
---|
142 | { |
---|
143 | ( *scheduler->Operations.unblock )( scheduler, the_thread ); |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * @brief Scheduler allocate. |
---|
148 | * |
---|
149 | * This routine allocates @a the_thread->scheduler |
---|
150 | */ |
---|
151 | RTEMS_INLINE_ROUTINE bool _Scheduler_Allocate( |
---|
152 | const Scheduler_Control *scheduler, |
---|
153 | Thread_Control *the_thread |
---|
154 | ) |
---|
155 | { |
---|
156 | return ( *scheduler->Operations.allocate )( scheduler, the_thread ); |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * @brief Scheduler free. |
---|
161 | * |
---|
162 | * This routine frees @a the_thread->scheduler |
---|
163 | */ |
---|
164 | RTEMS_INLINE_ROUTINE void _Scheduler_Free( |
---|
165 | const Scheduler_Control *scheduler, |
---|
166 | Thread_Control *the_thread |
---|
167 | ) |
---|
168 | { |
---|
169 | ( *scheduler->Operations.free )( scheduler, the_thread ); |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * @brief Scheduler update. |
---|
174 | * |
---|
175 | * This routine updates @a the_thread->scheduler |
---|
176 | */ |
---|
177 | RTEMS_INLINE_ROUTINE void _Scheduler_Update( |
---|
178 | const Scheduler_Control *scheduler, |
---|
179 | Thread_Control *the_thread |
---|
180 | ) |
---|
181 | { |
---|
182 | ( *scheduler->Operations.update )( scheduler, the_thread ); |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * @brief Scheduler enqueue. |
---|
187 | * |
---|
188 | * This routine enqueue @a the_thread->scheduler |
---|
189 | */ |
---|
190 | RTEMS_INLINE_ROUTINE void _Scheduler_Enqueue( |
---|
191 | const Scheduler_Control *scheduler, |
---|
192 | Thread_Control *the_thread |
---|
193 | ) |
---|
194 | { |
---|
195 | ( *scheduler->Operations.enqueue )( scheduler, the_thread ); |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * @brief Scheduler enqueue first. |
---|
200 | * |
---|
201 | * This routine enqueue_first @a the_thread->scheduler |
---|
202 | */ |
---|
203 | RTEMS_INLINE_ROUTINE void _Scheduler_Enqueue_first( |
---|
204 | const Scheduler_Control *scheduler, |
---|
205 | Thread_Control *the_thread |
---|
206 | ) |
---|
207 | { |
---|
208 | ( *scheduler->Operations.enqueue_first )( scheduler, the_thread ); |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * @brief Scheduler extract. |
---|
213 | * |
---|
214 | * This routine extract @a the_thread->scheduler |
---|
215 | */ |
---|
216 | RTEMS_INLINE_ROUTINE void _Scheduler_Extract( |
---|
217 | const Scheduler_Control *scheduler, |
---|
218 | Thread_Control *the_thread |
---|
219 | ) |
---|
220 | { |
---|
221 | ( *scheduler->Operations.extract )( scheduler, the_thread ); |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | * @brief Scheduler priority compare. |
---|
226 | * |
---|
227 | * This routine compares two priorities. |
---|
228 | */ |
---|
229 | RTEMS_INLINE_ROUTINE int _Scheduler_Priority_compare( |
---|
230 | const Scheduler_Control *scheduler, |
---|
231 | Priority_Control p1, |
---|
232 | Priority_Control p2 |
---|
233 | ) |
---|
234 | { |
---|
235 | return ( *scheduler->Operations.priority_compare )( p1, p2 ); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * @brief Scheduler release job. |
---|
240 | * |
---|
241 | * This routine is called when a new period of task is issued. |
---|
242 | */ |
---|
243 | RTEMS_INLINE_ROUTINE void _Scheduler_Release_job( |
---|
244 | const Scheduler_Control *scheduler, |
---|
245 | Thread_Control *the_thread, |
---|
246 | uint32_t length |
---|
247 | ) |
---|
248 | { |
---|
249 | ( *scheduler->Operations.release_job )( scheduler, the_thread, length ); |
---|
250 | } |
---|
251 | |
---|
252 | /** |
---|
253 | * @brief Scheduler method invoked at each clock tick. |
---|
254 | * |
---|
255 | * This method is invoked at each clock tick to allow the scheduler |
---|
256 | * implementation to perform any activities required. For the |
---|
257 | * scheduler which support standard RTEMS features, this includes |
---|
258 | * time-slicing management. |
---|
259 | */ |
---|
260 | RTEMS_INLINE_ROUTINE void _Scheduler_Tick( void ) |
---|
261 | { |
---|
262 | uint32_t cpu_count = _SMP_Get_processor_count(); |
---|
263 | uint32_t cpu_index; |
---|
264 | |
---|
265 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
266 | const Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
267 | const Scheduler_Control *scheduler = _Scheduler_Get_by_CPU( cpu ); |
---|
268 | |
---|
269 | if ( scheduler != NULL ) { |
---|
270 | ( *scheduler->Operations.tick )( scheduler, cpu->executing ); |
---|
271 | } |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | /** |
---|
276 | * @brief Starts the idle thread for a particular processor. |
---|
277 | * |
---|
278 | * @param[in,out] the_thread The idle thread for the processor. |
---|
279 | * @parma[in,out] processor The processor for the idle thread. |
---|
280 | * |
---|
281 | * @see _Thread_Create_idle(). |
---|
282 | */ |
---|
283 | RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle( |
---|
284 | const Scheduler_Control *scheduler, |
---|
285 | Thread_Control *the_thread, |
---|
286 | Per_CPU_Control *cpu |
---|
287 | ) |
---|
288 | { |
---|
289 | ( *scheduler->Operations.start_idle )( scheduler, the_thread, cpu ); |
---|
290 | } |
---|
291 | |
---|
292 | #if defined(RTEMS_SMP) |
---|
293 | RTEMS_INLINE_ROUTINE const Scheduler_Assignment *_Scheduler_Get_assignment( |
---|
294 | uint32_t cpu_index |
---|
295 | ) |
---|
296 | { |
---|
297 | return &_Scheduler_Assignments[ cpu_index ]; |
---|
298 | } |
---|
299 | |
---|
300 | RTEMS_INLINE_ROUTINE bool _Scheduler_Is_mandatory_processor( |
---|
301 | const Scheduler_Assignment *assignment |
---|
302 | ) |
---|
303 | { |
---|
304 | return (assignment->attributes & SCHEDULER_ASSIGN_PROCESSOR_MANDATORY) != 0; |
---|
305 | } |
---|
306 | |
---|
307 | RTEMS_INLINE_ROUTINE bool _Scheduler_Should_start_processor( |
---|
308 | const Scheduler_Assignment *assignment |
---|
309 | ) |
---|
310 | { |
---|
311 | return assignment->scheduler != NULL; |
---|
312 | } |
---|
313 | #endif /* defined(RTEMS_SMP) */ |
---|
314 | |
---|
315 | RTEMS_INLINE_ROUTINE bool _Scheduler_Has_processor_ownership( |
---|
316 | const Scheduler_Control *scheduler, |
---|
317 | uint32_t cpu_index |
---|
318 | ) |
---|
319 | { |
---|
320 | #if defined(RTEMS_SMP) |
---|
321 | const Scheduler_Assignment *assignment = |
---|
322 | _Scheduler_Get_assignment( cpu_index ); |
---|
323 | |
---|
324 | return assignment->scheduler == scheduler; |
---|
325 | #else |
---|
326 | (void) scheduler; |
---|
327 | (void) cpu_index; |
---|
328 | |
---|
329 | return true; |
---|
330 | #endif |
---|
331 | } |
---|
332 | |
---|
333 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) |
---|
334 | |
---|
335 | RTEMS_INLINE_ROUTINE void _Scheduler_Get_processor_set( |
---|
336 | const Scheduler_Control *scheduler, |
---|
337 | size_t cpusetsize, |
---|
338 | cpu_set_t *cpuset |
---|
339 | ) |
---|
340 | { |
---|
341 | uint32_t cpu_count = _SMP_Get_processor_count(); |
---|
342 | uint32_t cpu_index; |
---|
343 | |
---|
344 | CPU_ZERO_S( cpusetsize, cpuset ); |
---|
345 | |
---|
346 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
347 | #if defined(RTEMS_SMP) |
---|
348 | if ( _Scheduler_Has_processor_ownership( scheduler, cpu_index ) ) { |
---|
349 | CPU_SET_S( (int) cpu_index, cpusetsize, cpuset ); |
---|
350 | } |
---|
351 | #else |
---|
352 | (void) scheduler; |
---|
353 | |
---|
354 | CPU_SET_S( (int) cpu_index, cpusetsize, cpuset ); |
---|
355 | #endif |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | RTEMS_INLINE_ROUTINE bool _Scheduler_default_Get_affinity_body( |
---|
360 | const Scheduler_Control *scheduler, |
---|
361 | Thread_Control *the_thread, |
---|
362 | size_t cpusetsize, |
---|
363 | cpu_set_t *cpuset |
---|
364 | ) |
---|
365 | { |
---|
366 | (void) the_thread; |
---|
367 | |
---|
368 | _Scheduler_Get_processor_set( scheduler, cpusetsize, cpuset ); |
---|
369 | |
---|
370 | return true; |
---|
371 | } |
---|
372 | |
---|
373 | bool _Scheduler_Get_affinity( |
---|
374 | const Scheduler_Control *scheduler, |
---|
375 | Thread_Control *the_thread, |
---|
376 | size_t cpusetsize, |
---|
377 | cpu_set_t *cpuset |
---|
378 | ); |
---|
379 | |
---|
380 | RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get( |
---|
381 | Thread_Control *the_thread |
---|
382 | ) |
---|
383 | { |
---|
384 | #if defined(RTEMS_SMP) |
---|
385 | return the_thread->scheduler; |
---|
386 | #else |
---|
387 | (void) the_thread; |
---|
388 | |
---|
389 | return &_Scheduler_Table[ 0 ]; |
---|
390 | #endif |
---|
391 | } |
---|
392 | |
---|
393 | RTEMS_INLINE_ROUTINE bool _Scheduler_Set( |
---|
394 | const Scheduler_Control *scheduler, |
---|
395 | Thread_Control *the_thread |
---|
396 | ) |
---|
397 | { |
---|
398 | bool ok; |
---|
399 | |
---|
400 | if ( _States_Is_dormant( the_thread->current_state ) ) { |
---|
401 | #if defined(RTEMS_SMP) |
---|
402 | _Scheduler_Free( _Scheduler_Get( the_thread ), the_thread ); |
---|
403 | the_thread->scheduler = scheduler; |
---|
404 | _Scheduler_Allocate( scheduler, the_thread ); |
---|
405 | _Scheduler_Update( scheduler, the_thread ); |
---|
406 | #else |
---|
407 | (void) scheduler; |
---|
408 | #endif |
---|
409 | |
---|
410 | ok = true; |
---|
411 | } else { |
---|
412 | ok = false; |
---|
413 | } |
---|
414 | |
---|
415 | return ok; |
---|
416 | } |
---|
417 | |
---|
418 | RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body( |
---|
419 | const Scheduler_Control *scheduler, |
---|
420 | Thread_Control *the_thread, |
---|
421 | size_t cpusetsize, |
---|
422 | const cpu_set_t *cpuset |
---|
423 | ) |
---|
424 | { |
---|
425 | size_t cpu_max = _CPU_set_Maximum_CPU_count( cpusetsize ); |
---|
426 | uint32_t cpu_count = _SMP_Get_processor_count(); |
---|
427 | uint32_t cpu_index; |
---|
428 | bool ok = true; |
---|
429 | |
---|
430 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
431 | #if defined(RTEMS_SMP) |
---|
432 | const Scheduler_Control *scheduler_of_cpu = |
---|
433 | _Scheduler_Get_by_CPU_index( cpu_index ); |
---|
434 | |
---|
435 | ok = ok |
---|
436 | && ( ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset ) |
---|
437 | && scheduler == scheduler_of_cpu ) |
---|
438 | || ( !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset ) |
---|
439 | && scheduler != scheduler_of_cpu ) ); |
---|
440 | #else |
---|
441 | (void) scheduler; |
---|
442 | |
---|
443 | ok = ok && CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset ); |
---|
444 | #endif |
---|
445 | } |
---|
446 | |
---|
447 | for ( ; cpu_index < cpu_max ; ++cpu_index ) { |
---|
448 | ok = ok && !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset ); |
---|
449 | } |
---|
450 | |
---|
451 | if ( ok ) { |
---|
452 | ok = _Scheduler_Set( scheduler, the_thread ); |
---|
453 | } |
---|
454 | |
---|
455 | return ok; |
---|
456 | } |
---|
457 | |
---|
458 | bool _Scheduler_Set_affinity( |
---|
459 | Thread_Control *the_thread, |
---|
460 | size_t cpusetsize, |
---|
461 | const cpu_set_t *cpuset |
---|
462 | ); |
---|
463 | |
---|
464 | #endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */ |
---|
465 | |
---|
466 | RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir( |
---|
467 | Thread_Control *heir, |
---|
468 | bool force_dispatch |
---|
469 | ) |
---|
470 | { |
---|
471 | Thread_Control *executing = _Thread_Executing; |
---|
472 | |
---|
473 | _Thread_Heir = heir; |
---|
474 | |
---|
475 | if ( executing != heir && ( force_dispatch || executing->is_preemptible ) ) |
---|
476 | _Thread_Dispatch_necessary = true; |
---|
477 | } |
---|
478 | |
---|
479 | RTEMS_INLINE_ROUTINE void _Scheduler_Generic_block( |
---|
480 | const Scheduler_Control *scheduler, |
---|
481 | Thread_Control *the_thread, |
---|
482 | void ( *extract )( |
---|
483 | const Scheduler_Control *, |
---|
484 | Thread_Control * ), |
---|
485 | void ( *schedule )( |
---|
486 | const Scheduler_Control *, |
---|
487 | Thread_Control *, |
---|
488 | bool ) |
---|
489 | ) |
---|
490 | { |
---|
491 | ( *extract )( scheduler, the_thread ); |
---|
492 | |
---|
493 | /* TODO: flash critical section? */ |
---|
494 | |
---|
495 | if ( _Thread_Is_executing( the_thread ) || _Thread_Is_heir( the_thread ) ) { |
---|
496 | ( *schedule )( scheduler, the_thread, true ); |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | /** |
---|
501 | * @brief Returns true if @p1 encodes a lower priority than @a p2 in the |
---|
502 | * intuitive sense of priority. |
---|
503 | */ |
---|
504 | RTEMS_INLINE_ROUTINE bool _Scheduler_Is_priority_lower_than( |
---|
505 | const Scheduler_Control *scheduler, |
---|
506 | Priority_Control p1, |
---|
507 | Priority_Control p2 |
---|
508 | ) |
---|
509 | { |
---|
510 | return _Scheduler_Priority_compare( scheduler, p1, p2 ) < 0; |
---|
511 | } |
---|
512 | |
---|
513 | /** |
---|
514 | * @brief Returns true if @p1 encodes a higher priority than @a p2 in the |
---|
515 | * intuitive sense of priority. |
---|
516 | */ |
---|
517 | RTEMS_INLINE_ROUTINE bool _Scheduler_Is_priority_higher_than( |
---|
518 | const Scheduler_Control *scheduler, |
---|
519 | Priority_Control p1, |
---|
520 | Priority_Control p2 |
---|
521 | ) |
---|
522 | { |
---|
523 | return _Scheduler_Priority_compare( scheduler, p1, p2 ) > 0; |
---|
524 | } |
---|
525 | |
---|
526 | /** |
---|
527 | * @brief Returns the priority encoding @a p1 or @a p2 with the higher priority |
---|
528 | * in the intuitive sense of priority. |
---|
529 | */ |
---|
530 | RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Highest_priority_of_two( |
---|
531 | const Scheduler_Control *scheduler, |
---|
532 | Priority_Control p1, |
---|
533 | Priority_Control p2 |
---|
534 | ) |
---|
535 | { |
---|
536 | return _Scheduler_Is_priority_higher_than( scheduler, p1, p2 ) ? p1 : p2; |
---|
537 | } |
---|
538 | |
---|
539 | /** |
---|
540 | * @brief Sets the thread priority to @a priority if it is higher than the |
---|
541 | * current priority of the thread in the intuitive sense of priority. |
---|
542 | */ |
---|
543 | RTEMS_INLINE_ROUTINE void _Scheduler_Set_priority_if_higher( |
---|
544 | const Scheduler_Control *scheduler, |
---|
545 | Thread_Control *the_thread, |
---|
546 | Priority_Control priority |
---|
547 | ) |
---|
548 | { |
---|
549 | Priority_Control current = the_thread->current_priority; |
---|
550 | |
---|
551 | if ( _Scheduler_Is_priority_higher_than( scheduler, priority, current ) ) { |
---|
552 | _Thread_Set_priority( the_thread, priority ); |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | /** |
---|
557 | * @brief Changes the thread priority to @a priority if it is higher than the |
---|
558 | * current priority of the thread in the intuitive sense of priority. |
---|
559 | */ |
---|
560 | RTEMS_INLINE_ROUTINE void _Scheduler_Change_priority_if_higher( |
---|
561 | const Scheduler_Control *scheduler, |
---|
562 | Thread_Control *the_thread, |
---|
563 | Priority_Control priority, |
---|
564 | bool prepend_it |
---|
565 | ) |
---|
566 | { |
---|
567 | Priority_Control current = the_thread->current_priority; |
---|
568 | |
---|
569 | if ( _Scheduler_Is_priority_higher_than( scheduler, priority, current ) ) { |
---|
570 | _Thread_Change_priority( the_thread, priority, prepend_it ); |
---|
571 | } |
---|
572 | } |
---|
573 | |
---|
574 | RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index ) |
---|
575 | { |
---|
576 | return _Objects_Build_id( |
---|
577 | OBJECTS_FAKE_OBJECTS_API, |
---|
578 | OBJECTS_FAKE_OBJECTS_SCHEDULERS, |
---|
579 | _Objects_Local_node, |
---|
580 | scheduler_index + 1 |
---|
581 | ); |
---|
582 | } |
---|
583 | |
---|
584 | RTEMS_INLINE_ROUTINE bool _Scheduler_Get_by_id( |
---|
585 | Objects_Id id, |
---|
586 | const Scheduler_Control **scheduler |
---|
587 | ) |
---|
588 | { |
---|
589 | uint32_t minimum_id = _Scheduler_Build_id( 0 ); |
---|
590 | uint32_t index = id - minimum_id; |
---|
591 | |
---|
592 | *scheduler = &_Scheduler_Table[ index ]; |
---|
593 | |
---|
594 | return index < _Scheduler_Count; |
---|
595 | } |
---|
596 | |
---|
597 | RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_index( |
---|
598 | const Scheduler_Control *scheduler |
---|
599 | ) |
---|
600 | { |
---|
601 | return (uint32_t) (scheduler - &_Scheduler_Table[ 0 ]); |
---|
602 | } |
---|
603 | |
---|
604 | /** @} */ |
---|
605 | |
---|
606 | #ifdef __cplusplus |
---|
607 | } |
---|
608 | #endif |
---|
609 | |
---|
610 | #endif |
---|
611 | /* end of include file */ |
---|