RTEMS
tasksetpriority.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/rtems/tasksimpl.h>
23 #include <rtems/score/threadimpl.h>
24 
25 static 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 );
45  }
46 
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 
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 );
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 }
#define RTEMS_CURRENT_PRIORITY
This constant is passed to {set-priority:/name}() when the caller wants to obtain the current priorit...
Definition: tasks.h:248
static __inline__ Priority_Control _RTEMS_Priority_To_core(const Scheduler_Control *scheduler, rtems_task_priority priority, bool *valid)
Converts the RTEMS API priority to the corresponding SuperCore priority and validates it...
Definition: tasksimpl.h:96
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:70
This status code indicates that an invalid thread priority was provided.
Definition: status.h:189
static __inline__ Per_CPU_Control * _Thread_queue_Dispatch_disable(Thread_queue_Context *queue_context)
Disables dispatching in a critical section.
Definition: threadqimpl.h:429
Thread queue context for the thread queue methods.
Definition: threadq.h:198
static __inline__ const Scheduler_Control * _Thread_Scheduler_get_home(const Thread_Control *the_thread)
Gets the home scheduler of the thread.
Definition: threadimpl.h:1419
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
Per CPU Core Structure.
Definition: percpu.h:347
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
rtems_status_code rtems_task_set_priority(rtems_id id, rtems_task_priority new_priority, rtems_task_priority *old_priority_p)
%
static __inline__ Priority_Control _Thread_Get_priority(const Thread_Control *the_thread)
Returns the priority of the thread.
Definition: threadimpl.h:1610
void _Thread_Priority_update(Thread_queue_Context *queue_context)
Updates the priority of all threads in the set.
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
static __inline__ void _Thread_queue_Context_clear_priority_updates(Thread_queue_Context *queue_context)
Clears the priority update count of the thread queue context.
Definition: threadqimpl.h:338
This status code indicates that a specified address was invalid.
Definition: status.h:133
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
Inlined Routines from the Thread Handler.
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__ void _Thread_Priority_change(Thread_Control *the_thread, Priority_Node *priority_node, Priority_Control new_priority, bool prepend_it, Thread_queue_Context *queue_context)
Changes the thread priority value of the specified thread priority node in the corresponding thread p...
Definition: threadimpl.h:722
Priority_Node Real_priority
The base priority of this thread in its home scheduler instance.
Definition: thread.h:754
Classic Tasks Manager Implementation.