1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Task Set Affinity |
---|
5 | * @ingroup ClassicTasks Tasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) |
---|
22 | |
---|
23 | #include <rtems/rtems/tasks.h> |
---|
24 | #include <rtems/score/threadimpl.h> |
---|
25 | #include <rtems/score/cpusetimpl.h> |
---|
26 | #include <rtems/score/schedulerimpl.h> |
---|
27 | |
---|
28 | rtems_status_code rtems_task_set_affinity( |
---|
29 | rtems_id id, |
---|
30 | size_t cpusetsize, |
---|
31 | const cpu_set_t *cpuset |
---|
32 | ) |
---|
33 | { |
---|
34 | Thread_Control *the_thread; |
---|
35 | ISR_lock_Context lock_context; |
---|
36 | Per_CPU_Control *cpu_self; |
---|
37 | bool ok; |
---|
38 | |
---|
39 | if ( cpuset == NULL ) { |
---|
40 | return RTEMS_INVALID_ADDRESS; |
---|
41 | } |
---|
42 | |
---|
43 | the_thread = _Thread_Get( id, &lock_context ); |
---|
44 | |
---|
45 | if ( the_thread == NULL ) { |
---|
46 | #if defined(RTEMS_MULTIPROCESSING) |
---|
47 | if ( _Thread_MP_Is_remote( id ) ) { |
---|
48 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
49 | } |
---|
50 | #endif |
---|
51 | |
---|
52 | return RTEMS_INVALID_ID; |
---|
53 | } |
---|
54 | |
---|
55 | cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); |
---|
56 | _Thread_State_acquire_critical( the_thread, &lock_context ); |
---|
57 | |
---|
58 | ok = _Scheduler_Set_affinity( |
---|
59 | the_thread, |
---|
60 | cpusetsize, |
---|
61 | cpuset |
---|
62 | ); |
---|
63 | |
---|
64 | _Thread_State_release( the_thread, &lock_context ); |
---|
65 | _Thread_Dispatch_enable( cpu_self ); |
---|
66 | return ok ? RTEMS_SUCCESSFUL : RTEMS_INVALID_NUMBER; |
---|
67 | } |
---|
68 | #endif |
---|