RTEMS
taskgetpriority.c
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 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include <rtems/rtems/tasksimpl.h>
21 #include <rtems/score/threadimpl.h>
22 
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 ) ) {
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 }
rtems_status_code rtems_task_get_priority(rtems_id task_id, rtems_id scheduler_id, rtems_task_priority *priority)
%
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:70
Thread queue context for the thread queue methods.
Definition: threadq.h:198
static __inline__ Scheduler_Node * _Thread_Scheduler_get_node_by_index(const Thread_Control *the_thread, size_t scheduler_index)
Gets the thread&#39;s scheduler node by index.
Definition: threadimpl.h:1460
Inlined Routines Associated with the Manipulation of the Scheduler.
static __inline__ void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:152
Thread_Control * _Thread_Get(Objects_Id id, ISR_lock_Context *lock_context)
Gets a thread by its identifier.
Definition: threadget.c:24
uint32_t rtems_task_priority
%
Definition: tasks.h:94
static __inline__ void _Thread_Wait_acquire_critical(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Acquires the thread wait lock inside a critical section (interrupts disabled).
Definition: threadimpl.h:1812
This status code indicates successful completion.
Definition: status.h:86
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
This status code indicates that a specified address was invalid.
Definition: status.h:133
static __inline__ bool _Priority_Is_empty(const Priority_Aggregation *aggregation)
Checks if the priority aggregation is empty.
Definition: priorityimpl.h:256
struct Scheduler_Node::@20 Wait
Thread wait support block.
This status code indicates that the item has not been initialized.
Definition: status.h:143
This status code indicates that an object identifier was invalid.
Definition: status.h:106
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
Scheduler control.
Definition: scheduler.h:264
Scheduler node for per-thread data.
Definition: schedulernode.h:79
This status code indicates that the operation was illegal on a remote object.
Definition: status.h:177
Inlined Routines from the Thread Handler.
static __inline__ Priority_Control _Priority_Get_priority(const Priority_Aggregation *aggregation)
Gets the priority aggregation&#39;s priority.
Definition: priorityimpl.h:270
static __inline__ rtems_task_priority _RTEMS_Priority_From_core(const Scheduler_Control *scheduler, Priority_Control priority)
Converts the SuperCore priority to the corresponding RTEMS API priority.
Definition: tasksimpl.h:116
static __inline__ void _Thread_Wait_release(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Releases the thread wait lock and restores the previous interrupt status.
Definition: threadimpl.h:1929
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
static __inline__ uint32_t _Scheduler_Get_index(const Scheduler_Control *scheduler)
Gets the index of the scheduler.
static __inline__ const Scheduler_Control * _Scheduler_Get_by_id(Objects_Id id)
Gets the scheduler from the given object build id.
Classic Tasks Manager Implementation.