source: rtems/cpukit/rtems/src/taskgetpriority.c @ 8123cae8

5
Last change on this file since 8123cae8 was 8123cae8, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/16 at 13:32:22

rtems: Add rtems_task_get_priority()

Update #2556.
Update #2784.

  • Property mode set to 100644
File size: 1.9 KB
Line 
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
23rtems_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  if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
40    return RTEMS_INVALID_ID;
41  }
42
43  _Thread_queue_Context_initialize( &queue_context );
44  the_thread = _Thread_Get( task_id,
45    &queue_context.Lock_context.Lock_context
46  );
47
48  if ( the_thread == NULL ) {
49#if defined(RTEMS_MULTIPROCESSING)
50    if ( _Thread_MP_Is_remote( task_id ) ) {
51      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
52    }
53#endif
54
55    return RTEMS_INVALID_ID;
56  }
57
58  scheduler_node = _Thread_Scheduler_get_node_by_index(
59     the_thread,
60    _Scheduler_Get_index( scheduler )
61  );
62
63  _Thread_Wait_acquire_critical( the_thread, &queue_context );
64
65#if defined(RTEMS_SMP)
66  if ( _Priority_Is_empty( &scheduler_node->Wait.Priority ) ) {
67    _Thread_Wait_release( the_thread, &queue_context );
68    return RTEMS_NOT_DEFINED;
69  }
70#endif
71
72  core_priority = _Priority_Get_priority( &scheduler_node->Wait.Priority );
73
74  _Thread_Wait_release( the_thread, &queue_context );
75  *priority = _RTEMS_Priority_From_core( scheduler, core_priority );
76  return RTEMS_SUCCESSFUL;
77}
Note: See TracBrowser for help on using the repository browser.