source: rtems/cpukit/rtems/src/tasksetpriority.c @ 66cb142

5
Last change on this file since 66cb142 was db3a3de, checked in by Sebastian Huber <sebastian.huber@…>, on 10/10/17 at 08:03:48

score: Add _Thread_queue_Dispatch_disable()

  • 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_Priority_change(
48    the_thread,
49    &the_thread->Real_priority,
50    core_new_priority,
51    false,
52    queue_context
53  );
54  cpu_self = _Thread_queue_Dispatch_disable( queue_context );
55  _Thread_Wait_release( the_thread, queue_context );
56  _Thread_Priority_update( queue_context );
57  _Thread_Dispatch_enable( cpu_self );
58  return RTEMS_SUCCESSFUL;
59}
60
61rtems_status_code rtems_task_set_priority(
62  rtems_id             id,
63  rtems_task_priority  new_priority,
64  rtems_task_priority *old_priority_p
65)
66{
67  Thread_Control          *the_thread;
68  Thread_queue_Context     queue_context;
69  const Scheduler_Control *scheduler;
70  Priority_Control         old_priority;
71  rtems_status_code        status;
72
73  if ( old_priority_p == NULL ) {
74    return RTEMS_INVALID_ADDRESS;
75  }
76
77  _Thread_queue_Context_initialize( &queue_context );
78  _Thread_queue_Context_clear_priority_updates( &queue_context );
79  the_thread = _Thread_Get( id, &queue_context.Lock_context.Lock_context );
80
81  if ( the_thread == NULL ) {
82#if defined(RTEMS_MULTIPROCESSING)
83    return _RTEMS_tasks_MP_Set_priority( id, new_priority, old_priority_p );
84#else
85    return RTEMS_INVALID_ID;
86#endif
87  }
88
89  _Thread_Wait_acquire_critical( the_thread, &queue_context );
90
91  scheduler = _Thread_Scheduler_get_home( the_thread );
92  old_priority = _Thread_Get_priority( the_thread );
93
94  if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
95    status = _RTEMS_tasks_Set_priority(
96      the_thread,
97      scheduler,
98      new_priority,
99      &queue_context
100    );
101  } else {
102    _Thread_Wait_release( the_thread, &queue_context );
103    status = RTEMS_SUCCESSFUL;
104  }
105
106  *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
107  return status;
108}
Note: See TracBrowser for help on using the repository browser.