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/tasks.h> |
---|
20 | #include <rtems/score/schedulerimpl.h> |
---|
21 | |
---|
22 | rtems_status_code rtems_task_set_scheduler( |
---|
23 | rtems_id task_id, |
---|
24 | rtems_id scheduler_id |
---|
25 | ) |
---|
26 | { |
---|
27 | const Scheduler_Control *scheduler; |
---|
28 | Thread_Control *the_thread; |
---|
29 | ISR_lock_Context lock_context; |
---|
30 | ISR_lock_Context state_lock_context; |
---|
31 | Per_CPU_Control *cpu_self; |
---|
32 | void *lock; |
---|
33 | bool ok; |
---|
34 | |
---|
35 | if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) { |
---|
36 | return RTEMS_INVALID_ID; |
---|
37 | } |
---|
38 | |
---|
39 | the_thread = _Thread_Get_interrupt_disable( task_id, &lock_context ); |
---|
40 | |
---|
41 | if ( the_thread == NULL ) { |
---|
42 | #if defined(RTEMS_MULTIPROCESSING) |
---|
43 | if ( _Thread_MP_Is_remote( task_id ) ) { |
---|
44 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
45 | } |
---|
46 | #endif |
---|
47 | |
---|
48 | return RTEMS_INVALID_ID; |
---|
49 | } |
---|
50 | |
---|
51 | cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); |
---|
52 | _ISR_lock_ISR_enable( &lock_context ); |
---|
53 | |
---|
54 | lock = _Thread_Lock_acquire( the_thread, &lock_context ); |
---|
55 | _Thread_State_acquire_critical( the_thread, &state_lock_context ); |
---|
56 | |
---|
57 | ok = _Scheduler_Set( scheduler, the_thread ); |
---|
58 | |
---|
59 | _Thread_State_release_critical( the_thread, &state_lock_context ); |
---|
60 | _Thread_Lock_release( lock, &lock_context ); |
---|
61 | _Thread_Dispatch_enable( cpu_self ); |
---|
62 | return ok ? RTEMS_SUCCESSFUL : RTEMS_INCORRECT_STATE; |
---|
63 | } |
---|