source: rtems/cpukit/rtems/src/tasksetscheduler.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: 1.9 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_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}
Note: See TracBrowser for help on using the repository browser.