From 900d337f960cb7cc53f5c93c29a503e5ced2c31f Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 5 May 2015 13:05:54 +0200 Subject: score: Rework _Thread_Change_priority() Move the writes to Thread_Control::current_priority and Thread_Control::real_priority into _Thread_Change_priority() under the protection of the thread lock. Add a filter function to _Thread_Change_priority() to enable specialized variants. Avoid race conditions during a thread priority restore with the new Thread_Control::priority_restore_hint for an important average case optimizations used by priority inheritance mutexes. Update #2273. --- cpukit/score/src/coremutexsurrender.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'cpukit/score/src/coremutexsurrender.c') diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c index 3f0cd8619c..d5dde1e8e6 100644 --- a/cpukit/score/src/coremutexsurrender.c +++ b/cpukit/score/src/coremutexsurrender.c @@ -207,14 +207,10 @@ CORE_mutex_Status _CORE_mutex_Surrender( case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING: _CORE_mutex_Push_priority( the_mutex, the_thread ); the_thread->resource_count++; - if (the_mutex->Attributes.priority_ceiling < - the_thread->current_priority){ - _Thread_Change_priority( - the_thread, - the_mutex->Attributes.priority_ceiling, - false - ); - } + _Thread_Raise_priority( + the_thread, + the_mutex->Attributes.priority_ceiling + ); break; } } @@ -246,13 +242,20 @@ CORE_mutex_Status _CORE_mutex_Surrender( * inherited priority must be lowered if this is the last * mutex (i.e. resource) this task has. */ - if ( !_Thread_Owns_resources( holder ) && - holder->real_priority != holder->current_priority ) { - Per_CPU_Control *cpu_self; + if ( !_Thread_Owns_resources( holder ) ) { + /* + * Ensure that the holder resource count is visible to all other processors + * and that we read the latest priority restore hint. + */ + _Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); - cpu_self = _Thread_Dispatch_disable(); - _Thread_Change_priority( holder, holder->real_priority, true ); - _Thread_Dispatch_enable( cpu_self ); + if ( holder->priority_restore_hint ) { + Per_CPU_Control *cpu_self; + + cpu_self = _Thread_Dispatch_disable(); + _Thread_Restore_priority( holder ); + _Thread_Dispatch_enable( cpu_self ); + } } return CORE_MUTEX_STATUS_SUCCESSFUL; -- cgit v1.2.3