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

5
Last change on this file since d78d529 was 2612a0b, checked in by Sebastian Huber <sebastian.huber@…>, on 11/02/16 at 05:36:13

score: Simplify _Scheduler_Get_by_id()

Avoid dead code in non-SMP configurations. Return scheduler identifier
independent of the current processor count of the scheduler via
rtems_scheduler_ident(), since this value may change during run-time.
Check the processor count in _Scheduler_Set() under scheduler lock
protection.

Update #2797.

  • Property mode set to 100644
File size: 2.0 KB
Line 
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#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/rtems/tasksimpl.h>
20#include <rtems/rtems/statusimpl.h>
21#include <rtems/score/schedulerimpl.h>
22
23rtems_status_code rtems_task_set_scheduler(
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 ) {
45    return RTEMS_INVALID_PRIORITY;
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 ) ) {
54      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
55    }
56#endif
57
58    return RTEMS_INVALID_ID;
59  }
60
61  cpu_self = _Thread_Dispatch_disable_critical(
62    &queue_context.Lock_context.Lock_context
63  );
64
65  _Thread_Wait_acquire_critical( the_thread, &queue_context );
66  _Thread_State_acquire_critical( the_thread, &state_context );
67
68  status = _Scheduler_Set( scheduler, the_thread, core_priority );
69
70  _Thread_State_release_critical( the_thread, &state_context );
71  _Thread_Wait_release( the_thread, &queue_context );
72  _Thread_Dispatch_enable( cpu_self );
73  return _Status_Get( status );
74}
Note: See TracBrowser for help on using the repository browser.