RTEMS
taskgetscheduler.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/tasks.h>
21 
23  rtems_id task_id,
24  rtems_id *scheduler_id
25 )
26 {
27  Thread_Control *the_thread;
28  ISR_lock_Context lock_context;
29  const Scheduler_Control *scheduler;
30 
31  if ( scheduler_id == NULL ) {
32  return RTEMS_INVALID_ADDRESS;
33  }
34 
35  the_thread = _Thread_Get( task_id, &lock_context );
36 
37  if ( the_thread == NULL ) {
38 #if defined(RTEMS_MULTIPROCESSING)
39  if ( _Thread_MP_Is_remote( task_id ) ) {
41  }
42 #endif
43 
44  return RTEMS_INVALID_ID;
45  }
46 
47  _Thread_State_acquire_critical( the_thread, &lock_context );
48 
49  scheduler = _Thread_Scheduler_get_home( the_thread );
50  *scheduler_id = _Scheduler_Build_id( _Scheduler_Get_index( scheduler ) );
51 
52  _Thread_State_release( the_thread, &lock_context );
53  return RTEMS_SUCCESSFUL;
54 }
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__ 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.
Thread_Control * _Thread_Get(Objects_Id id, ISR_lock_Context *lock_context)
Gets a thread by its identifier.
Definition: threadget.c:24
static __inline__ void _Thread_State_release(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the lock context and enables interrupts.
Definition: threadimpl.h:592
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
This header file defines the main parts of the Tasks Manager API.
This status code indicates that a specified address was invalid.
Definition: status.h:133
static __inline__ Objects_Id _Scheduler_Build_id(uint32_t scheduler_index)
Builds an object build id.
rtems_status_code rtems_task_get_scheduler(rtems_id task_id, rtems_id *scheduler_id)
%
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__ uint32_t _Scheduler_Get_index(const Scheduler_Control *scheduler)
Gets the index of the scheduler.