[1b475860] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Changes the Priority of a Thread |
---|
[05df0a8] | 5 | * |
---|
[1b475860] | 6 | * @ingroup ScoreThread |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[108c4b0] | 10 | * COPYRIGHT (c) 1989-2011. |
---|
[05df0a8] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
[dcf3687] | 14 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[05df0a8] | 16 | */ |
---|
| 17 | |
---|
[a8eed23] | 18 | #if HAVE_CONFIG_H |
---|
| 19 | #include "config.h" |
---|
| 20 | #endif |
---|
| 21 | |
---|
[5618c37a] | 22 | #include <rtems/score/threadimpl.h> |
---|
[c6e21ee1] | 23 | #include <rtems/score/schedulerimpl.h> |
---|
[a112364] | 24 | #include <rtems/score/threadqimpl.h> |
---|
[05df0a8] | 25 | |
---|
| 26 | void _Thread_Change_priority( |
---|
| 27 | Thread_Control *the_thread, |
---|
| 28 | Priority_Control new_priority, |
---|
[484a769] | 29 | bool prepend_it |
---|
[05df0a8] | 30 | ) |
---|
| 31 | { |
---|
[96d0b64] | 32 | /* |
---|
| 33 | * Do not bother recomputing all the priority related information if |
---|
| 34 | * we are not REALLY changing priority. |
---|
| 35 | */ |
---|
[f39f667a] | 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 ); |
---|
[96d0b64] | 63 | } |
---|
[f39f667a] | 64 | _ISR_Enable( level ); |
---|
[96d0b64] | 65 | |
---|
[f39f667a] | 66 | _Thread_queue_Requeue( the_thread->Wait.queue, the_thread ); |
---|
[d9aca5f5] | 67 | } |
---|
[05df0a8] | 68 | } |
---|