From 4edf348c3395560bcaaf3c020968e427f5683d28 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 22 May 2014 09:31:13 +0200 Subject: score: PR2179: Fix initially locked PCP mutexes Elevate the priority of the creating task to the ceiling priority in case a semaphore is created as initially locked. --- cpukit/score/src/coremutex.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c index 96b11c9cd1..e13c7aafac 100644 --- a/cpukit/score/src/coremutex.c +++ b/cpukit/score/src/coremutex.c @@ -43,10 +43,20 @@ CORE_mutex_Status _CORE_mutex_Initialize( the_mutex->holder = executing; if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) || _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) { + Priority_Control ceiling = the_mutex->Attributes.priority_ceiling; + + /* + * The mutex initialization is only protected by the allocator lock in + * general. Disable thread dispatching before the priority check to + * prevent interference with priority inheritance. + */ + _Thread_Disable_dispatch(); + + if ( executing->current_priority < ceiling ) { + _Thread_Enable_dispatch(); + return CORE_MUTEX_STATUS_CEILING_VIOLATED; + } - if ( executing->current_priority < - the_mutex->Attributes.priority_ceiling ) - return CORE_MUTEX_STATUS_CEILING_VIOLATED; #ifdef __RTEMS_STRICT_ORDER_MUTEX__ _Chain_Prepend_unprotected( &executing->lock_mutex, &the_mutex->queue.lock_queue ); @@ -54,6 +64,9 @@ CORE_mutex_Status _CORE_mutex_Initialize( #endif executing->resource_count++; + + _Thread_Change_priority( executing, ceiling, false ); + _Thread_Enable_dispatch(); } } else { the_mutex->nest_count = 0; -- cgit v1.2.3