[c05d7502] | 1 | /** |
---|
| 2 | * @file |
---|
[c4d69e2] | 3 | * |
---|
[c05d7502] | 4 | * @brief RTEMS Set Task Priority |
---|
| 5 | * @ingroup ClassicTasks |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[8d7c3ca] | 9 | * COPYRIGHT (c) 1989-2014. |
---|
[c4d69e2] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[c4d69e2] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[c404828] | 21 | #include <rtems/rtems/tasksimpl.h> |
---|
[5618c37a] | 22 | #include <rtems/score/threadimpl.h> |
---|
[c4d69e2] | 23 | |
---|
| 24 | rtems_status_code rtems_task_set_priority( |
---|
[d3b72ca3] | 25 | rtems_id id, |
---|
[c4d69e2] | 26 | rtems_task_priority new_priority, |
---|
| 27 | rtems_task_priority *old_priority |
---|
| 28 | ) |
---|
| 29 | { |
---|
[3a638ce] | 30 | Thread_Control *the_thread; |
---|
[1a0ccc7] | 31 | Objects_Locations location; |
---|
[c4d69e2] | 32 | |
---|
| 33 | if ( new_priority != RTEMS_CURRENT_PRIORITY && |
---|
| 34 | !_RTEMS_tasks_Priority_is_valid( new_priority ) ) |
---|
| 35 | return RTEMS_INVALID_PRIORITY; |
---|
| 36 | |
---|
[0860426] | 37 | if ( !old_priority ) |
---|
| 38 | return RTEMS_INVALID_ADDRESS; |
---|
| 39 | |
---|
[c4d69e2] | 40 | the_thread = _Thread_Get( id, &location ); |
---|
| 41 | switch ( location ) { |
---|
| 42 | |
---|
[ebe61382] | 43 | case OBJECTS_LOCAL: |
---|
[2bafb960] | 44 | *old_priority = _RTEMS_tasks_Priority_from_Core( |
---|
| 45 | the_thread->current_priority |
---|
| 46 | ); |
---|
[ebe61382] | 47 | if ( new_priority != RTEMS_CURRENT_PRIORITY ) { |
---|
[2bafb960] | 48 | the_thread->real_priority = _RTEMS_tasks_Priority_to_Core( |
---|
| 49 | new_priority |
---|
| 50 | ); |
---|
[ebe61382] | 51 | if ( the_thread->resource_count == 0 || |
---|
| 52 | the_thread->current_priority > new_priority ) |
---|
[eaef4657] | 53 | _Thread_Change_priority( the_thread, new_priority, false ); |
---|
[ebe61382] | 54 | } |
---|
[2d2352b] | 55 | _Objects_Put( &the_thread->Object ); |
---|
[ebe61382] | 56 | return RTEMS_SUCCESSFUL; |
---|
| 57 | |
---|
[c4d69e2] | 58 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[0e87deaa] | 59 | case OBJECTS_REMOTE: |
---|
[c4d69e2] | 60 | _Thread_Executing->Wait.return_argument = old_priority; |
---|
| 61 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
| 62 | RTEMS_TASKS_MP_SET_PRIORITY_REQUEST, |
---|
| 63 | id, |
---|
| 64 | new_priority, |
---|
| 65 | 0, /* Not used */ |
---|
| 66 | 0 /* Not used */ |
---|
| 67 | ); |
---|
| 68 | #endif |
---|
| 69 | |
---|
| 70 | case OBJECTS_ERROR: |
---|
[ebe61382] | 71 | break; |
---|
[c4d69e2] | 72 | } |
---|
| 73 | |
---|
[ebe61382] | 74 | return RTEMS_INVALID_ID; |
---|
[c4d69e2] | 75 | } |
---|