From e135271b933c896068a343b161773ce3b685be43 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 11 May 2016 10:58:59 +0200 Subject: score: Avoid Giant lock _Scheduler_Set_affinity() Update #2555. --- cpukit/rtems/src/tasksetaffinity.c | 43 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'cpukit/rtems/src/tasksetaffinity.c') diff --git a/cpukit/rtems/src/tasksetaffinity.c b/cpukit/rtems/src/tasksetaffinity.c index a7a18be4d5..6389e4c795 100644 --- a/cpukit/rtems/src/tasksetaffinity.c +++ b/cpukit/rtems/src/tasksetaffinity.c @@ -31,33 +31,38 @@ rtems_status_code rtems_task_set_affinity( const cpu_set_t *cpuset ) { - Thread_Control *the_thread; - Objects_Locations location; - int ok; + Thread_Control *the_thread; + ISR_lock_Context lock_context; + Per_CPU_Control *cpu_self; + bool ok; - if ( !cpuset ) + if ( cpuset == NULL ) { return RTEMS_INVALID_ADDRESS; + } - the_thread = _Thread_Get( id, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - ok = _Scheduler_Set_affinity( - the_thread, - cpusetsize, - cpuset - ); - _Objects_Put( &the_thread->Object ); - return ok ? RTEMS_SUCCESSFUL : RTEMS_INVALID_NUMBER; + the_thread = _Thread_Get_interrupt_disable( id, &lock_context ); + if ( the_thread == NULL ) { #if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: + if ( _Thread_MP_Is_remote( id ) ) { + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + } #endif - case OBJECTS_ERROR: - break; + return RTEMS_INVALID_ID; } - return RTEMS_INVALID_ID; + cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); + _Thread_State_acquire_critical( the_thread, &lock_context ); + + ok = _Scheduler_Set_affinity( + the_thread, + cpusetsize, + cpuset + ); + + _Thread_State_release( the_thread, &lock_context ); + _Thread_Dispatch_enable( cpu_self ); + return ok ? RTEMS_SUCCESSFUL : RTEMS_INVALID_NUMBER; } #endif -- cgit v1.2.3