1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Pthread Set Affinity |
---|
5 | * @ingroup POSIXAPI |
---|
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 HAVE_DECL_PTHREAD_SETAFFINITY_NP |
---|
22 | |
---|
23 | #define _GNU_SOURCE |
---|
24 | #include <pthread.h> |
---|
25 | #include <errno.h> |
---|
26 | |
---|
27 | #include <rtems/posix/pthreadimpl.h> |
---|
28 | #include <rtems/posix/priorityimpl.h> |
---|
29 | #include <rtems/score/threadimpl.h> |
---|
30 | #include <rtems/score/cpusetimpl.h> |
---|
31 | #include <rtems/score/schedulerimpl.h> |
---|
32 | |
---|
33 | int pthread_setaffinity_np( |
---|
34 | pthread_t thread, |
---|
35 | size_t cpusetsize, |
---|
36 | const cpu_set_t *cpuset |
---|
37 | ) |
---|
38 | { |
---|
39 | Thread_Control *the_thread; |
---|
40 | ISR_lock_Context lock_context; |
---|
41 | Per_CPU_Control *cpu_self; |
---|
42 | bool ok; |
---|
43 | |
---|
44 | if ( cpuset == NULL ) { |
---|
45 | return EFAULT; |
---|
46 | } |
---|
47 | |
---|
48 | the_thread = _Thread_Get( thread, &lock_context ); |
---|
49 | |
---|
50 | if ( the_thread == NULL ) { |
---|
51 | return ESRCH; |
---|
52 | } |
---|
53 | |
---|
54 | cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); |
---|
55 | _Thread_State_acquire_critical( the_thread, &lock_context ); |
---|
56 | |
---|
57 | ok = _Scheduler_Set_affinity( |
---|
58 | the_thread, |
---|
59 | cpusetsize, |
---|
60 | cpuset |
---|
61 | ); |
---|
62 | |
---|
63 | if ( ok ) { |
---|
64 | POSIX_API_Control *api; |
---|
65 | |
---|
66 | api = the_thread->API_Extensions[ THREAD_API_POSIX ]; |
---|
67 | CPU_COPY( api->Attributes.affinityset, cpuset ); |
---|
68 | } |
---|
69 | |
---|
70 | _Thread_State_release( the_thread, &lock_context ); |
---|
71 | _Thread_Dispatch_enable( cpu_self ); |
---|
72 | return ok ? 0 : EINVAL; |
---|
73 | } |
---|
74 | #endif |
---|