1 | /* |
---|
2 | * RTEMS Task Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1998. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/rtems/status.h> |
---|
18 | #include <rtems/rtems/support.h> |
---|
19 | #include <rtems/rtems/modes.h> |
---|
20 | #include <rtems/score/object.h> |
---|
21 | #include <rtems/score/stack.h> |
---|
22 | #include <rtems/score/states.h> |
---|
23 | #include <rtems/rtems/tasks.h> |
---|
24 | #include <rtems/score/thread.h> |
---|
25 | #include <rtems/score/threadq.h> |
---|
26 | #include <rtems/score/tod.h> |
---|
27 | #include <rtems/score/userext.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | #include <rtems/score/apiext.h> |
---|
30 | #include <rtems/score/sysstate.h> |
---|
31 | |
---|
32 | /*PAGE |
---|
33 | * |
---|
34 | * rtems_task_set_priority |
---|
35 | * |
---|
36 | * This directive changes the priority of the specified thread. |
---|
37 | * The specified thread can be any thread in the system including |
---|
38 | * the requesting thread. |
---|
39 | * |
---|
40 | * Input parameters: |
---|
41 | * id - thread id (0 indicates requesting thread) |
---|
42 | * new_priority - thread priority (0 indicates current priority) |
---|
43 | * old_priority - pointer to previous priority |
---|
44 | * |
---|
45 | * Output parameters: |
---|
46 | * old_priority - previous priority |
---|
47 | * RTEMS_SUCCESSFUL - if successful |
---|
48 | * error code - if unsuccessful |
---|
49 | */ |
---|
50 | |
---|
51 | rtems_status_code rtems_task_set_priority( |
---|
52 | Objects_Id id, |
---|
53 | rtems_task_priority new_priority, |
---|
54 | rtems_task_priority *old_priority |
---|
55 | ) |
---|
56 | { |
---|
57 | register Thread_Control *the_thread; |
---|
58 | Objects_Locations location; |
---|
59 | |
---|
60 | if ( new_priority != RTEMS_CURRENT_PRIORITY && |
---|
61 | !_RTEMS_tasks_Priority_is_valid( new_priority ) ) |
---|
62 | return RTEMS_INVALID_PRIORITY; |
---|
63 | |
---|
64 | if ( !old_priority ) |
---|
65 | return RTEMS_INVALID_ADDRESS; |
---|
66 | |
---|
67 | the_thread = _Thread_Get( id, &location ); |
---|
68 | switch ( location ) { |
---|
69 | |
---|
70 | case OBJECTS_REMOTE: |
---|
71 | #if defined(RTEMS_MULTIPROCESSING) |
---|
72 | _Thread_Executing->Wait.return_argument = old_priority; |
---|
73 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
74 | RTEMS_TASKS_MP_SET_PRIORITY_REQUEST, |
---|
75 | id, |
---|
76 | new_priority, |
---|
77 | 0, /* Not used */ |
---|
78 | 0 /* Not used */ |
---|
79 | ); |
---|
80 | #endif |
---|
81 | |
---|
82 | case OBJECTS_ERROR: |
---|
83 | return RTEMS_INVALID_ID; |
---|
84 | |
---|
85 | case OBJECTS_LOCAL: |
---|
86 | *old_priority = the_thread->current_priority; |
---|
87 | if ( new_priority != RTEMS_CURRENT_PRIORITY ) { |
---|
88 | the_thread->real_priority = new_priority; |
---|
89 | if ( the_thread->resource_count == 0 || |
---|
90 | the_thread->current_priority > new_priority ) |
---|
91 | _Thread_Change_priority( the_thread, new_priority, FALSE ); |
---|
92 | } |
---|
93 | _Thread_Enable_dispatch(); |
---|
94 | return RTEMS_SUCCESSFUL; |
---|
95 | } |
---|
96 | |
---|
97 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
98 | } |
---|