1 | /* |
---|
2 | * Copyright (c) 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/rtems/tasksimpl.h> |
---|
20 | #include <rtems/score/schedulerimpl.h> |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | |
---|
23 | rtems_status_code rtems_task_get_priority( |
---|
24 | rtems_id task_id, |
---|
25 | rtems_id scheduler_id, |
---|
26 | rtems_task_priority *priority |
---|
27 | ) |
---|
28 | { |
---|
29 | Thread_Control *the_thread; |
---|
30 | Thread_queue_Context queue_context; |
---|
31 | const Scheduler_Control *scheduler; |
---|
32 | const Scheduler_Node *scheduler_node; |
---|
33 | Priority_Control core_priority; |
---|
34 | |
---|
35 | if ( priority == NULL ) { |
---|
36 | return RTEMS_INVALID_ADDRESS; |
---|
37 | } |
---|
38 | |
---|
39 | scheduler = _Scheduler_Get_by_id( scheduler_id ); |
---|
40 | if ( scheduler == NULL ) { |
---|
41 | return RTEMS_INVALID_ID; |
---|
42 | } |
---|
43 | |
---|
44 | _Thread_queue_Context_initialize( &queue_context ); |
---|
45 | the_thread = _Thread_Get( task_id, |
---|
46 | &queue_context.Lock_context.Lock_context |
---|
47 | ); |
---|
48 | |
---|
49 | if ( the_thread == NULL ) { |
---|
50 | #if defined(RTEMS_MULTIPROCESSING) |
---|
51 | if ( _Thread_MP_Is_remote( task_id ) ) { |
---|
52 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
53 | } |
---|
54 | #endif |
---|
55 | |
---|
56 | return RTEMS_INVALID_ID; |
---|
57 | } |
---|
58 | |
---|
59 | scheduler_node = _Thread_Scheduler_get_node_by_index( |
---|
60 | the_thread, |
---|
61 | _Scheduler_Get_index( scheduler ) |
---|
62 | ); |
---|
63 | |
---|
64 | _Thread_Wait_acquire_critical( the_thread, &queue_context ); |
---|
65 | |
---|
66 | #if defined(RTEMS_SMP) |
---|
67 | if ( _Priority_Is_empty( &scheduler_node->Wait.Priority ) ) { |
---|
68 | _Thread_Wait_release( the_thread, &queue_context ); |
---|
69 | return RTEMS_NOT_DEFINED; |
---|
70 | } |
---|
71 | #endif |
---|
72 | |
---|
73 | core_priority = _Priority_Get_priority( &scheduler_node->Wait.Priority ); |
---|
74 | |
---|
75 | _Thread_Wait_release( the_thread, &queue_context ); |
---|
76 | *priority = _RTEMS_Priority_From_core( scheduler, core_priority ); |
---|
77 | return RTEMS_SUCCESSFUL; |
---|
78 | } |
---|