diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-11 13:42:58 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-12 13:24:41 +0200 |
commit | 8bc6bf28aa098a03c25763e3c59274874bfbe3da (patch) | |
tree | c7b1434c02d96b48cba14c3bcfeb2c865c4f816f /cpukit/posix/src/pthreadsetschedparam.c | |
parent | score: Avoid Giant lock _Scheduler_Get_affinity() (diff) | |
download | rtems-8bc6bf28aa098a03c25763e3c59274874bfbe3da.tar.bz2 |
posix: Avoid Giant lock for some pthread functions
Avoid Giant lock for pthread_getattr_np(), pthread_setschedparam() and
pthread_getschedparam(). Replace POSIX threads scheduler lock with
thread state lock.
Update #2555.
Diffstat (limited to 'cpukit/posix/src/pthreadsetschedparam.c')
-rw-r--r-- | cpukit/posix/src/pthreadsetschedparam.c | 123 |
1 files changed, 60 insertions, 63 deletions
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c index 57a2bc8ce1..8f3cc206e1 100644 --- a/cpukit/posix/src/pthreadsetschedparam.c +++ b/cpukit/posix/src/pthreadsetschedparam.c @@ -38,11 +38,11 @@ int pthread_setschedparam( ) { Thread_Control *the_thread; + Per_CPU_Control *cpu_self; POSIX_API_Control *api; Thread_CPU_budget_algorithms budget_algorithm; Thread_CPU_budget_algorithm_callout budget_callout; - Objects_Locations location; - int rc; + int eno; Priority_Control unused; ISR_lock_Context lock_context; Priority_Control new_priority; @@ -50,79 +50,76 @@ int pthread_setschedparam( /* * Check all the parameters */ - if ( !param ) + + if ( param == NULL ) { return EINVAL; + } - rc = _POSIX_Thread_Translate_sched_param( + eno = _POSIX_Thread_Translate_sched_param( policy, param, &budget_algorithm, &budget_callout ); - if ( rc ) - return rc; + if ( eno != 0 ) { + return eno; + } + + the_thread = _Thread_Get_interrupt_disable( thread, &lock_context ); + + if ( the_thread == NULL ) { + return ESRCH; + } /* * Actually change the scheduling policy and parameters */ - the_thread = _Thread_Get( thread, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - api = the_thread->API_Extensions[ THREAD_API_POSIX ]; - - _POSIX_Threads_Scheduler_acquire( api, &lock_context ); - - if ( api->schedpolicy == SCHED_SPORADIC ) { - _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer ); - } - - api->schedpolicy = policy; - api->schedparam = *param; - api->Attributes.schedpolicy = policy; - api->Attributes.schedparam = *param; - - the_thread->budget_algorithm = budget_algorithm; - the_thread->budget_callout = budget_callout; - - switch ( policy ) { - case SCHED_OTHER: - case SCHED_FIFO: - case SCHED_RR: - the_thread->cpu_time_budget = - rtems_configuration_get_ticks_per_timeslice(); - new_priority = - _POSIX_Priority_To_core( api->schedparam.sched_priority ); - break; - - case SCHED_SPORADIC: - api->ss_high_priority = api->schedparam.sched_priority; - break; - } - - _POSIX_Threads_Scheduler_release( api, &lock_context ); - - switch ( policy ) { - case SCHED_OTHER: - case SCHED_FIFO: - case SCHED_RR: - _Thread_Set_priority( the_thread, new_priority, &unused, true ); - break; - - case SCHED_SPORADIC: - _POSIX_Threads_Sporadic_budget_TSR( &api->Sporadic_timer ); - break; - } - - _Objects_Put( &the_thread->Object ); - return 0; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: + + cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); + _Thread_State_acquire_critical( the_thread, &lock_context ); + + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + + if ( api->schedpolicy == SCHED_SPORADIC ) { + _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer ); + } + + api->schedpolicy = policy; + api->schedparam = *param; + api->Attributes.schedpolicy = policy; + api->Attributes.schedparam = *param; + + the_thread->budget_algorithm = budget_algorithm; + the_thread->budget_callout = budget_callout; + + switch ( policy ) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + the_thread->cpu_time_budget = + rtems_configuration_get_ticks_per_timeslice(); + new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority ); + break; + + case SCHED_SPORADIC: + api->ss_high_priority = api->schedparam.sched_priority; + break; + } + + _Thread_State_release( the_thread, &lock_context ); + + switch ( policy ) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + _Thread_Set_priority( the_thread, new_priority, &unused, true ); + break; + + case SCHED_SPORADIC: + _POSIX_Threads_Sporadic_budget_TSR( &api->Sporadic_timer ); break; } - return ESRCH; + _Thread_Dispatch_enable( cpu_self ); + return 0; } |