RTEMS
tasksetscheduler.c
1 /*
2  * Copyright (c) 2014 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>
20 #include <rtems/rtems/statusimpl.h>
22 
24  rtems_id task_id,
25  rtems_id scheduler_id,
26  rtems_task_priority priority
27 )
28 {
29  const Scheduler_Control *scheduler;
30  Thread_Control *the_thread;
31  Thread_queue_Context queue_context;
32  ISR_lock_Context state_context;
33  Per_CPU_Control *cpu_self;
34  bool valid;
35  Priority_Control core_priority;
36  Status_Control status;
37 
38  scheduler = _Scheduler_Get_by_id( scheduler_id );
39  if ( scheduler == NULL ) {
40  return RTEMS_INVALID_ID;
41  }
42 
43  core_priority = _RTEMS_Priority_To_core( scheduler, priority, &valid );
44  if ( !valid ) {
46  }
47 
48  _Thread_queue_Context_initialize( &queue_context );
49  the_thread = _Thread_Get( task_id, &queue_context.Lock_context.Lock_context );
50 
51  if ( the_thread == NULL ) {
52 #if defined(RTEMS_MULTIPROCESSING)
53  if ( _Thread_MP_Is_remote( task_id ) ) {
55  }
56 #endif
57 
58  return RTEMS_INVALID_ID;
59  }
60 
61  cpu_self = _Thread_queue_Dispatch_disable( &queue_context );
62  _Thread_Wait_acquire_critical( the_thread, &queue_context );
63  _Thread_State_acquire_critical( the_thread, &state_context );
64 
65  status = _Scheduler_Set( scheduler, the_thread, core_priority );
66 
67  _Thread_State_release_critical( the_thread, &state_context );
68  _Thread_Wait_release( the_thread, &queue_context );
69  _Thread_Dispatch_enable( cpu_self );
70  return _Status_Get( status );
71 }
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__ void _Thread_State_release_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Release the lock context in a critical section.
Definition: threadimpl.h:578
static __inline__ void _Thread_State_acquire_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Acquires the lock context in a critical section.
Definition: threadimpl.h:528
static __inline__ Status_Control _Scheduler_Set(const Scheduler_Control *new_scheduler, Thread_Control *the_thread, Priority_Control priority)
Sets a new scheduler.
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
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
Classic Status Implementation.
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
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
This status code indicates that the operation was illegal on a remote object.
Definition: status.h:177
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
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
rtems_status_code rtems_task_set_scheduler(rtems_id task_id, rtems_id scheduler_id, rtems_task_priority priority)
%
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
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.