1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Set Task Priority |
---|
5 | * @ingroup ClassicTasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
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 |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/rtems/tasksimpl.h> |
---|
22 | #include <rtems/score/threadimpl.h> |
---|
23 | |
---|
24 | rtems_status_code rtems_task_set_priority( |
---|
25 | rtems_id id, |
---|
26 | rtems_task_priority new_priority, |
---|
27 | rtems_task_priority *old_priority |
---|
28 | ) |
---|
29 | { |
---|
30 | Thread_Control *the_thread; |
---|
31 | Objects_Locations location; |
---|
32 | |
---|
33 | if ( new_priority != RTEMS_CURRENT_PRIORITY && |
---|
34 | !_RTEMS_tasks_Priority_is_valid( new_priority ) ) |
---|
35 | return RTEMS_INVALID_PRIORITY; |
---|
36 | |
---|
37 | if ( !old_priority ) |
---|
38 | return RTEMS_INVALID_ADDRESS; |
---|
39 | |
---|
40 | the_thread = _Thread_Get( id, &location ); |
---|
41 | switch ( location ) { |
---|
42 | |
---|
43 | case OBJECTS_LOCAL: |
---|
44 | *old_priority = _RTEMS_tasks_Priority_from_Core( |
---|
45 | the_thread->current_priority |
---|
46 | ); |
---|
47 | if ( new_priority != RTEMS_CURRENT_PRIORITY ) { |
---|
48 | the_thread->real_priority = _RTEMS_tasks_Priority_to_Core( |
---|
49 | new_priority |
---|
50 | ); |
---|
51 | if ( the_thread->resource_count == 0 || |
---|
52 | the_thread->current_priority > new_priority ) |
---|
53 | _Thread_Change_priority( the_thread, new_priority, false ); |
---|
54 | } |
---|
55 | _Objects_Put( &the_thread->Object ); |
---|
56 | return RTEMS_SUCCESSFUL; |
---|
57 | |
---|
58 | #if defined(RTEMS_MULTIPROCESSING) |
---|
59 | case OBJECTS_REMOTE: |
---|
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: |
---|
71 | break; |
---|
72 | } |
---|
73 | |
---|
74 | return RTEMS_INVALID_ID; |
---|
75 | } |
---|