source: rtems/cpukit/rtems/src/tasksetpriority.c @ d78d529

5
Last change on this file since d78d529 was 2dd098a, checked in by Sebastian Huber <sebastian.huber@…>, on 10/31/16 at 07:33:11

score: Introduce Thread_Scheduler_control::home

Replace Thread_Scheduler_control::control and
Thread_Scheduler_control::own_control with new
Thread_Scheduler_control::home.

Update #2556.

  • Property mode set to 100644
File size: 2.7 KB
Line 
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/schedulerimpl.h>
23#include <rtems/score/threadimpl.h>
24
25static rtems_status_code _RTEMS_tasks_Set_priority(
26  Thread_Control          *the_thread,
27  const Scheduler_Control *scheduler,
28  Priority_Control         new_priority,
29  Thread_queue_Context    *queue_context
30)
31{
32  Priority_Control core_new_priority;
33  bool             valid;
34  Per_CPU_Control *cpu_self;
35
36  core_new_priority = _RTEMS_Priority_To_core(
37    scheduler,
38    new_priority,
39    &valid
40  );
41
42  if ( !valid ) {
43    _Thread_Wait_release( the_thread, queue_context );
44    return RTEMS_INVALID_PRIORITY;
45  }
46
47  _Thread_queue_Context_clear_priority_updates( queue_context );
48  _Thread_Priority_change(
49    the_thread,
50    &the_thread->Real_priority,
51    core_new_priority,
52    false,
53    queue_context
54  );
55  cpu_self = _Thread_Dispatch_disable_critical(
56    &queue_context->Lock_context.Lock_context
57  );
58  _Thread_Wait_release( the_thread, queue_context );
59  _Thread_Priority_update( queue_context );
60  _Thread_Dispatch_enable( cpu_self );
61  return RTEMS_SUCCESSFUL;
62}
63
64rtems_status_code rtems_task_set_priority(
65  rtems_id             id,
66  rtems_task_priority  new_priority,
67  rtems_task_priority *old_priority_p
68)
69{
70  Thread_Control          *the_thread;
71  Thread_queue_Context     queue_context;
72  const Scheduler_Control *scheduler;
73  Priority_Control         old_priority;
74  rtems_status_code        status;
75
76  if ( old_priority_p == NULL ) {
77    return RTEMS_INVALID_ADDRESS;
78  }
79
80  _Thread_queue_Context_initialize( &queue_context );
81  the_thread = _Thread_Get( id, &queue_context.Lock_context.Lock_context );
82
83  if ( the_thread == NULL ) {
84#if defined(RTEMS_MULTIPROCESSING)
85    return _RTEMS_tasks_MP_Set_priority( id, new_priority, old_priority_p );
86#else
87    return RTEMS_INVALID_ID;
88#endif
89  }
90
91  _Thread_Wait_acquire_critical( the_thread, &queue_context );
92
93  scheduler = _Thread_Scheduler_get_home( the_thread );
94  old_priority = _Thread_Get_priority( the_thread );
95
96  if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
97    status = _RTEMS_tasks_Set_priority(
98      the_thread,
99      scheduler,
100      new_priority,
101      &queue_context
102    );
103  } else {
104    _Thread_Wait_release( the_thread, &queue_context );
105    status = RTEMS_SUCCESSFUL;
106  }
107
108  *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
109  return status;
110}
Note: See TracBrowser for help on using the repository browser.