diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-11 10:58:59 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-12 13:24:41 +0200 |
commit | e135271b933c896068a343b161773ce3b685be43 (patch) | |
tree | 83faf308498a9695ba551f8e5b3f7473daa37d68 /cpukit/posix/src/pthreadsetaffinitynp.c | |
parent | score: Use thread state lock for current state (diff) | |
download | rtems-e135271b933c896068a343b161773ce3b685be43.tar.bz2 |
score: Avoid Giant lock _Scheduler_Set_affinity()
Update #2555.
Diffstat (limited to 'cpukit/posix/src/pthreadsetaffinitynp.c')
-rw-r--r-- | cpukit/posix/src/pthreadsetaffinitynp.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c index 711d6dcaeb..6dd8bce224 100644 --- a/cpukit/posix/src/pthreadsetaffinitynp.c +++ b/cpukit/posix/src/pthreadsetaffinitynp.c @@ -31,41 +31,44 @@ #include <rtems/score/schedulerimpl.h> int pthread_setaffinity_np( - pthread_t id, - size_t cpusetsize, - const cpu_set_t *cpuset) + pthread_t thread, + size_t cpusetsize, + const cpu_set_t *cpuset +) { - Objects_Locations location; - POSIX_API_Control *api; - Thread_Control *the_thread; - bool ok; + Thread_Control *the_thread; + ISR_lock_Context lock_context; + Per_CPU_Control *cpu_self; + bool ok; - if ( !cpuset ) + if ( cpuset == NULL ) { return EFAULT; + } - the_thread = _Thread_Get( id, &location ); - switch ( location ) { + the_thread = _Thread_Get_interrupt_disable( thread, &lock_context ); - case OBJECTS_LOCAL: - ok = _Scheduler_Set_affinity( - the_thread, - cpusetsize, - cpuset - ); - if ( ok ) { - api = the_thread->API_Extensions[ THREAD_API_POSIX ]; - CPU_COPY( api->Attributes.affinityset, cpuset ); - } - _Objects_Put( &the_thread->Object ); - return ok ? 0 : EINVAL; + if ( the_thread == NULL ) { + return ESRCH; + } -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); + _Thread_State_acquire_critical( the_thread, &lock_context ); + + ok = _Scheduler_Set_affinity( + the_thread, + cpusetsize, + cpuset + ); + + if ( ok ) { + POSIX_API_Control *api; + + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + CPU_COPY( api->Attributes.affinityset, cpuset ); } - return ESRCH; + _Thread_State_release( the_thread, &lock_context ); + _Thread_Dispatch_enable( cpu_self ); + return ok ? 0 : EINVAL; } #endif |