1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Changes the Priority of a Thread |
---|
5 | * |
---|
6 | * @ingroup ScoreThread |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/score/threadimpl.h> |
---|
23 | #include <rtems/score/schedulerimpl.h> |
---|
24 | #include <rtems/score/threadqimpl.h> |
---|
25 | |
---|
26 | void _Thread_Change_priority( |
---|
27 | Thread_Control *the_thread, |
---|
28 | Priority_Control new_priority, |
---|
29 | bool prepend_it |
---|
30 | ) |
---|
31 | { |
---|
32 | /* |
---|
33 | * Do not bother recomputing all the priority related information if |
---|
34 | * we are not REALLY changing priority. |
---|
35 | */ |
---|
36 | if ( the_thread->current_priority != new_priority ) { |
---|
37 | ISR_Level level; |
---|
38 | const Scheduler_Control *scheduler; |
---|
39 | |
---|
40 | _ISR_Disable( level ); |
---|
41 | |
---|
42 | scheduler = _Scheduler_Get( the_thread ); |
---|
43 | the_thread->current_priority = new_priority; |
---|
44 | |
---|
45 | if ( _States_Is_ready( the_thread->current_state ) ) { |
---|
46 | _Scheduler_Change_priority( |
---|
47 | scheduler, |
---|
48 | the_thread, |
---|
49 | new_priority, |
---|
50 | prepend_it |
---|
51 | ); |
---|
52 | |
---|
53 | _ISR_Flash( level ); |
---|
54 | |
---|
55 | /* |
---|
56 | * We altered the set of thread priorities. So let's figure out |
---|
57 | * who is the heir and if we need to switch to them. |
---|
58 | */ |
---|
59 | scheduler = _Scheduler_Get( the_thread ); |
---|
60 | _Scheduler_Schedule( scheduler, the_thread ); |
---|
61 | } else { |
---|
62 | _Scheduler_Update( scheduler, the_thread ); |
---|
63 | } |
---|
64 | _ISR_Enable( level ); |
---|
65 | |
---|
66 | _Thread_queue_Requeue( the_thread->Wait.queue, the_thread ); |
---|
67 | } |
---|
68 | } |
---|