diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-30 06:59:55 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-30 16:16:23 +0200 |
commit | 0b713f8940d90b480f8cd36663c11aa0688587d8 (patch) | |
tree | c71a01748c3749e0243518b486c2bb32a1c67df1 /cpukit/score | |
parent | score: Rework CORE priority ceiling mutex (diff) | |
download | rtems-0b713f8940d90b480f8cd36663c11aa0688587d8.tar.bz2 |
score: Rework CORE inherit priority mutex
Provide dedicated seize and surrender methods for inherit priority
mutexes. This eliminates CORE_mutex_Attributes.
Diffstat (limited to 'cpukit/score')
-rw-r--r-- | cpukit/score/Makefile.am | 4 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/apimutex.h | 2 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/coremutex.h | 49 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/coremuteximpl.h | 263 | ||||
-rw-r--r-- | cpukit/score/src/apimutex.c | 6 | ||||
-rw-r--r-- | cpukit/score/src/apimutexisowner.c | 6 | ||||
-rw-r--r-- | cpukit/score/src/apimutexlock.c | 7 | ||||
-rw-r--r-- | cpukit/score/src/apimutexunlock.c | 8 | ||||
-rw-r--r-- | cpukit/score/src/coremutex.c | 53 | ||||
-rw-r--r-- | cpukit/score/src/coremutexseize.c | 17 | ||||
-rw-r--r-- | cpukit/score/src/coremutexsurrender.c | 127 | ||||
-rw-r--r-- | cpukit/score/src/debugisownerofallocator.c | 2 |
12 files changed, 159 insertions, 385 deletions
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index fae6fc37bb..29e822d47d 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -181,8 +181,8 @@ libscore_a_SOURCES += src/coremsg.c src/coremsgbroadcast.c \ src/coremsgsubmit.c ## CORE_MUTEX_C_FILES -libscore_a_SOURCES += src/coremutex.c \ - src/coremutexseize.c src/coremutexsurrender.c +libscore_a_SOURCES += src/coremutexseize.c +libscore_a_SOURCES += src/coremutexsurrender.c ## CORE_PERCPU_C_FILES libscore_a_SOURCES += src/percpu.c diff --git a/cpukit/score/include/rtems/score/apimutex.h b/cpukit/score/include/rtems/score/apimutex.h index 1a4b1ee445..aa08481c83 100644 --- a/cpukit/score/include/rtems/score/apimutex.h +++ b/cpukit/score/include/rtems/score/apimutex.h @@ -46,7 +46,7 @@ typedef struct { /** * Contains the SuperCore mutex information. */ - CORE_mutex_Control Mutex; + CORE_recursive_mutex_Control Mutex; /** * @brief The thread life protection state before the outer-most mutex diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h index 704ea0da24..2bde8b5ebd 100644 --- a/cpukit/score/include/rtems/score/coremutex.h +++ b/cpukit/score/include/rtems/score/coremutex.h @@ -42,47 +42,6 @@ extern "C" { /**@{*/ /** - * @brief The possible behaviors for lock nesting. - * - * This enumerated type defines the possible behaviors for - * lock nesting. - */ -typedef enum { - /** - * This sequence has no blocking or errors: - * - * + lock(m) - * + lock(m) - * + unlock(m) - * + unlock(m) - */ - CORE_MUTEX_NESTING_ACQUIRES, -#if defined(RTEMS_POSIX_API) - /** - * This sequence returns an error at the indicated point: - * - * + lock(m) - * + lock(m) - already locked error - * + unlock(m) - */ - CORE_MUTEX_NESTING_IS_ERROR, -#endif -} CORE_mutex_Nesting_behaviors; - -/** - * @brief The control block used to manage attributes of each mutex. - * - * The following defines the control block used to manage the - * attributes of each mutex. - */ -typedef struct { - /** This field determines what the behavior of this mutex instance will - * be when attempting to acquire the mutex when it is already locked. - */ - CORE_mutex_Nesting_behaviors lock_nesting_behavior; -} CORE_mutex_Attributes; - -/** * @brief Control block used to manage each mutex. * * The following defines the control block used to manage each mutex. @@ -93,14 +52,6 @@ typedef struct { */ Thread_queue_Control Wait_queue; - /** This element is the set of attributes which define this instance's - * behavior. - */ - CORE_mutex_Attributes Attributes; - /** This element contains the number of times the mutex has been acquired - * nested. This must be zero (0) before the mutex is actually unlocked. - */ - uint32_t nest_count; /** This element points to the thread which is currently holding this mutex. * The holder is the last thread to successfully lock the mutex and which * has not unlocked it. If the thread is not locked, there is no holder. diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h index f459743346..69311e4101 100644 --- a/cpukit/score/include/rtems/score/coremuteximpl.h +++ b/cpukit/score/include/rtems/score/coremuteximpl.h @@ -35,26 +35,13 @@ extern "C" { #define CORE_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority -/** - * @brief Initializes the mutex based on the parameters passed. - * - * This routine initializes the mutex based on the parameters passed. - * - * @param[in,out] the_mutex is the mutex to initalize - * @param[in,out] executing The currently executing thread. - * @param[in] the_mutex_attributes is the attributes associated with this - * mutex instance - * @param[in] initially_locked If true, then the mutex is initially locked by - * the executing thread. - * - * @retval This method returns STATUS_SUCCESSFUL if successful. - */ -Status_Control _CORE_mutex_Initialize( - CORE_mutex_Control *the_mutex, - Thread_Control *executing, - const CORE_mutex_Attributes *the_mutex_attributes, - bool initially_locked -); +RTEMS_INLINE_ROUTINE void _CORE_mutex_Initialize( + CORE_mutex_Control *the_mutex +) +{ + _Thread_queue_Initialize( &the_mutex->Wait_queue ); + the_mutex->holder = NULL; +} RTEMS_INLINE_ROUTINE void _CORE_mutex_Destroy( CORE_mutex_Control *the_mutex ) { @@ -83,25 +70,6 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Release( ); } -/** - * @brief Performs the blocking portion of a mutex obtain. - * - * This routine performs the blocking portion of a mutex obtain. - * It is an actual subroutine and is not implemented as something - * that may be inlined. - * - * @param[in,out] the_mutex is the mutex to attempt to lock - * @param[in,out] executing The currently executing thread. - * @param[in] timeout is the maximum number of ticks to block - * @param[in] lock_context is the interrupt level - */ -Status_Control _CORE_mutex_Seize_interrupt_blocking( - CORE_mutex_Control *the_mutex, - Thread_Control *executing, - Watchdog_Interval timeout, - Thread_queue_Context *queue_context -); - RTEMS_INLINE_ROUTINE Thread_Control *_CORE_mutex_Get_owner( const CORE_mutex_Control *the_mutex ) @@ -127,124 +95,14 @@ RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_locked( return _CORE_mutex_Get_owner( the_mutex ) != NULL; } -/** - * @brief Attempt to receive a unit from the_mutex. - * - * This routine attempts to receive a unit from the_mutex. - * If a unit is available or if the wait flag is false, then the routine - * returns. Otherwise, the calling task is blocked until a unit becomes - * available. - * - * @param[in,out] executing The currently executing thread. - * @param[in,out] the_mutex is the mutex to attempt to lock - * @param[in] queue_context is the interrupt level - * - * @retval STATUS_UNAVAILABLE The mutex is already locked. - * @retval other Otherwise. - */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_mutex_Seize_interrupt_trylock( - CORE_mutex_Control *the_mutex, - Thread_Control *executing, - Thread_queue_Context *queue_context -) -{ - /* disabled when you get here */ - - if ( !_CORE_mutex_Is_locked( the_mutex ) ) { - the_mutex->holder = executing; - the_mutex->nest_count = 1; - ++executing->resource_count; - - _CORE_mutex_Release( the_mutex, queue_context ); - return STATUS_SUCCESSFUL; - } - - /* - * At this point, we know the mutex was not available. If this thread - * is the thread that has locked the mutex, let's see if we are allowed - * to nest access. - */ - if ( _Thread_Is_executing( the_mutex->holder ) ) { - switch ( the_mutex->Attributes.lock_nesting_behavior ) { - case CORE_MUTEX_NESTING_ACQUIRES: - the_mutex->nest_count++; - _CORE_mutex_Release( the_mutex, queue_context ); - return STATUS_SUCCESSFUL; - #if defined(RTEMS_POSIX_API) - case CORE_MUTEX_NESTING_IS_ERROR: - _CORE_mutex_Release( the_mutex, queue_context ); - return STATUS_NESTING_NOT_ALLOWED; - #endif - } - } - - /* - * The mutex is not available and the caller must deal with the possibility - * of blocking. - */ - return STATUS_UNAVAILABLE; -} - -/** - * @brief Attempt to obtain the mutex. - * - * This routine attempts to obtain the mutex. If the mutex is available, - * then it will return immediately. Otherwise, it will invoke the - * support routine @a _Core_mutex_Seize_interrupt_blocking. - * - * @param[in] the_mutex is the mutex to attempt to lock - * @param[in] wait is true if the thread is willing to wait - * @param[in] timeout is the maximum number of ticks to block - * @param[in] queue_context is a temporary variable used to contain the ISR - * disable level cookie - * - * @note If the mutex is called from an interrupt service routine, - * with context switching disabled, or before multitasking, - * then a fatal error is generated. - * - * The logic on this routine is as follows: - * - * * If incorrect system state - * return an error - * * If mutex is available without any contention or blocking - * obtain it with interrupts disabled and returned - * * If the caller is willing to wait - * then they are blocked. - */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_mutex_Seize( +Status_Control _CORE_mutex_Seize_slow( CORE_mutex_Control *the_mutex, Thread_Control *executing, + Thread_Control *owner, bool wait, Watchdog_Interval timeout, Thread_queue_Context *queue_context -) -{ - Status_Control status; - - _CORE_mutex_Acquire_critical( the_mutex, queue_context ); - - status = _CORE_mutex_Seize_interrupt_trylock( - the_mutex, - executing, - queue_context - ); - - if ( status != STATUS_UNAVAILABLE ) { - return status; - } - - if ( !wait ) { - _CORE_mutex_Release( the_mutex, queue_context ); - return status; - } - - return _CORE_mutex_Seize_interrupt_blocking( - the_mutex, - executing, - timeout, - queue_context - ); -} +); Status_Control _CORE_mutex_Seize_no_protocol_slow( CORE_mutex_Control *the_mutex, @@ -255,8 +113,11 @@ Status_Control _CORE_mutex_Seize_no_protocol_slow( Thread_queue_Context *queue_context ); -Status_Control _CORE_mutex_Surrender( +Status_Control _CORE_mutex_Surrender_slow( CORE_mutex_Control *the_mutex, + Thread_Control *executing, + Thread_queue_Heads *heads, + bool keep_priority, Thread_queue_Context *queue_context ); @@ -306,8 +167,7 @@ RTEMS_INLINE_ROUTINE void _CORE_recursive_mutex_Initialize( CORE_recursive_mutex_Control *the_mutex ) { - _Thread_queue_Initialize( &the_mutex->Mutex.Wait_queue ); - the_mutex->Mutex.holder = NULL; + _CORE_mutex_Initialize( &the_mutex->Mutex ); the_mutex->nest_level = 0; } @@ -319,6 +179,99 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_nested( return STATUS_SUCCESSFUL; } +RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize( + CORE_recursive_mutex_Control *the_mutex, + Thread_Control *executing, + bool wait, + Watchdog_Interval timeout, + Status_Control ( *nested )( CORE_recursive_mutex_Control * ), + Thread_queue_Context *queue_context +) +{ + Thread_Control *owner; + + _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context ); + + owner = _CORE_mutex_Get_owner( &the_mutex->Mutex ); + + if ( owner == NULL ) { + _CORE_mutex_Set_owner( &the_mutex->Mutex, executing ); + ++executing->resource_count; + _CORE_mutex_Release( &the_mutex->Mutex, queue_context ); + return STATUS_SUCCESSFUL; + } + + if ( owner == executing ) { + Status_Control status; + + status = ( *nested )( the_mutex ); + _CORE_mutex_Release( &the_mutex->Mutex, queue_context ); + return status; + } + + return _CORE_mutex_Seize_slow( + &the_mutex->Mutex, + executing, + owner, + wait, + timeout, + queue_context + ); +} + +RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender( + CORE_recursive_mutex_Control *the_mutex, + Thread_Control *executing, + Thread_queue_Context *queue_context +) +{ + unsigned int nest_level; + Thread_queue_Heads *heads; + bool keep_priority; + + _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context ); + + if ( !_CORE_mutex_Is_owner( &the_mutex->Mutex, executing ) ) { + _CORE_mutex_Release( &the_mutex->Mutex, queue_context ); + return STATUS_NOT_OWNER; + } + + nest_level = the_mutex->nest_level; + + if ( nest_level > 0 ) { + the_mutex->nest_level = nest_level - 1; + _CORE_mutex_Release( &the_mutex->Mutex, queue_context ); + return STATUS_SUCCESSFUL; + } + + --executing->resource_count; + _CORE_mutex_Set_owner( &the_mutex->Mutex, NULL ); + + /* + * Ensure that the owner resource count is visible to all other + * processors and that we read the latest priority restore + * hint. + */ + _Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); + + heads = the_mutex->Mutex.Wait_queue.Queue.heads; + keep_priority = _Thread_Owns_resources( executing ) + || !executing->priority_restore_hint; + + if ( heads == NULL && keep_priority ) { + _CORE_mutex_Release( &the_mutex->Mutex, queue_context ); + return STATUS_SUCCESSFUL; + } + + return _CORE_mutex_Surrender_slow( + &the_mutex->Mutex, + executing, + heads, + keep_priority, + queue_context + ); +} + RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_no_protocol( CORE_recursive_mutex_Control *the_mutex, const Thread_queue_Operations *operations, diff --git a/cpukit/score/src/apimutex.c b/cpukit/score/src/apimutex.c index e3c6e5a705..ed5cfd5831 100644 --- a/cpukit/score/src/apimutex.c +++ b/cpukit/score/src/apimutex.c @@ -47,16 +47,12 @@ void _API_Mutex_Allocate( { API_Mutex_Control *mutex; - CORE_mutex_Attributes attr = { - CORE_MUTEX_NESTING_ACQUIRES - }; - mutex = (API_Mutex_Control *) _Objects_Allocate_unprotected( &_API_Mutex_Information ); _Assert( mutex != NULL ); - _CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, false ); + _CORE_recursive_mutex_Initialize( &mutex->Mutex ); _Objects_Open_u32( &_API_Mutex_Information, &mutex->Object, 1 ); diff --git a/cpukit/score/src/apimutexisowner.c b/cpukit/score/src/apimutexisowner.c index a80c664cb3..65b80ed5b3 100644 --- a/cpukit/score/src/apimutexisowner.c +++ b/cpukit/score/src/apimutexisowner.c @@ -18,9 +18,13 @@ #endif #include <rtems/score/apimutex.h> +#include <rtems/score/coremuteximpl.h> #include <rtems/score/threadimpl.h> bool _API_Mutex_Is_owner( const API_Mutex_Control *the_mutex ) { - return the_mutex->Mutex.holder == _Thread_Get_executing(); + return _CORE_mutex_Is_owner( + &the_mutex->Mutex.Mutex, + _Thread_Get_executing() + ); } diff --git a/cpukit/score/src/apimutexlock.c b/cpukit/score/src/apimutexlock.c index 7a7f911f84..df53e75256 100644 --- a/cpukit/score/src/apimutexlock.c +++ b/cpukit/score/src/apimutexlock.c @@ -34,15 +34,16 @@ void _API_Mutex_Lock( API_Mutex_Control *the_mutex ) _Thread_queue_Context_initialize( &queue_context ); _ISR_lock_ISR_disable( &queue_context.Lock_context ); - _CORE_mutex_Seize( + _CORE_recursive_mutex_Seize( &the_mutex->Mutex, _Thread_Executing, true, - 0, + WATCHDOG_NO_TIMEOUT, + _CORE_recursive_mutex_Seize_nested, &queue_context ); - if ( the_mutex->Mutex.nest_count == 1 ) { + if ( the_mutex->Mutex.nest_level == 0 ) { the_mutex->previous_thread_life_state = previous_thread_life_state; } } diff --git a/cpukit/score/src/apimutexunlock.c b/cpukit/score/src/apimutexunlock.c index 486301fa82..67188db144 100644 --- a/cpukit/score/src/apimutexunlock.c +++ b/cpukit/score/src/apimutexunlock.c @@ -29,11 +29,15 @@ void _API_Mutex_Unlock( API_Mutex_Control *the_mutex ) bool restore_thread_life_protection; previous_thread_life_state = the_mutex->previous_thread_life_state; - restore_thread_life_protection = the_mutex->Mutex.nest_count == 1; + restore_thread_life_protection = the_mutex->Mutex.nest_level == 0; _Thread_queue_Context_initialize( &queue_context ); _ISR_lock_ISR_disable( &queue_context.Lock_context ); - _CORE_mutex_Surrender( &the_mutex->Mutex, &queue_context ); + _CORE_recursive_mutex_Surrender( + &the_mutex->Mutex, + _Thread_Executing, + &queue_context + ); if ( restore_thread_life_protection ) { _Thread_Set_life_protection( previous_thread_life_state ); diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c deleted file mode 100644 index 9c6b7a8b93..0000000000 --- a/cpukit/score/src/coremutex.c +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file - * - * @brief Initialize a Core Mutex - * @ingroup ScoreMutex - */ - -/* - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <rtems/system.h> -#include <rtems/score/isr.h> -#include <rtems/score/coremuteximpl.h> -#include <rtems/score/thread.h> - -Status_Control _CORE_mutex_Initialize( - CORE_mutex_Control *the_mutex, - Thread_Control *executing, - const CORE_mutex_Attributes *the_mutex_attributes, - bool initially_locked -) -{ - -/* Add this to the RTEMS environment later ????????? - rtems_assert( initial_lock == CORE_MUTEX_LOCKED || - initial_lock == CORE_MUTEX_UNLOCKED ); - */ - - the_mutex->Attributes = *the_mutex_attributes; - - if ( initially_locked ) { - the_mutex->nest_count = 1; - the_mutex->holder = executing; - executing->resource_count++; - } else { - the_mutex->nest_count = 0; - the_mutex->holder = NULL; - } - - _Thread_queue_Initialize( &the_mutex->Wait_queue ); - - return STATUS_SUCCESSFUL; -} diff --git a/cpukit/score/src/coremutexseize.c b/cpukit/score/src/coremutexseize.c index ed5eb0aeec..ab743c4847 100644 --- a/cpukit/score/src/coremutexseize.c +++ b/cpukit/score/src/coremutexseize.c @@ -22,14 +22,19 @@ #include <rtems/score/statesimpl.h> #include <rtems/score/thread.h> -Status_Control _CORE_mutex_Seize_interrupt_blocking( +Status_Control _CORE_mutex_Seize_slow( CORE_mutex_Control *the_mutex, Thread_Control *executing, + Thread_Control *owner, + bool wait, Watchdog_Interval timeout, Thread_queue_Context *queue_context ) { - Thread_Control *holder; + if ( !wait ) { + _CORE_mutex_Release( the_mutex, queue_context ); + return STATUS_UNAVAILABLE; + } #if !defined(RTEMS_SMP) /* @@ -37,23 +42,19 @@ Status_Control _CORE_mutex_Seize_interrupt_blocking( * priority inheritance mutexes. */ _Thread_Dispatch_disable(); -#endif - - holder = the_mutex->holder; -#if !defined(RTEMS_SMP) /* * To enable interrupts here works only since exactly one executing thread * exists and only threads are allowed to seize and surrender mutexes with * the priority inheritance protocol. On SMP configurations more than one * executing thread may exist, so here we must not release the lock, since - * otherwise the current holder may be no longer the holder of the mutex + * otherwise the current owner may be no longer the owner of the mutex * once we released the lock. */ _CORE_mutex_Release( the_mutex, queue_context ); #endif - _Thread_Inherit_priority( holder, executing ); + _Thread_Inherit_priority( owner, executing ); #if defined(RTEMS_SMP) _Thread_queue_Context_set_expected_level( queue_context, 1 ); diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c index 5075e204c9..6604be89da 100644 --- a/cpukit/score/src/coremutexsurrender.c +++ b/cpukit/score/src/coremutexsurrender.c @@ -18,141 +18,58 @@ #include "config.h" #endif -#include <rtems/system.h> -#include <rtems/score/isr.h> #include <rtems/score/coremuteximpl.h> -#include <rtems/score/thread.h> -Status_Control _CORE_mutex_Surrender( +Status_Control _CORE_mutex_Surrender_slow( CORE_mutex_Control *the_mutex, + Thread_Control *executing, + Thread_queue_Heads *heads, + bool keep_priority, Thread_queue_Context *queue_context ) { - Thread_Control *the_thread; - Thread_Control *holder; + if ( heads != NULL ) { + const Thread_queue_Operations *operations; + Thread_Control *new_owner; + bool unblock; - holder = the_mutex->holder; + operations = CORE_MUTEX_TQ_OPERATIONS; + new_owner = ( *operations->first )( heads ); - /* - * Priority Ceiling or Priority Inheritance mutexes must be released by the - * thread which acquired them. - */ - if ( !_Thread_Is_executing( holder ) ) { - _ISR_lock_ISR_enable( &queue_context->Lock_context ); - return STATUS_NOT_OWNER; - } - - _CORE_mutex_Acquire_critical( the_mutex, queue_context ); - - /* XXX already unlocked -- not right status */ - - if ( !the_mutex->nest_count ) { - _CORE_mutex_Release( the_mutex, queue_context ); - return STATUS_SUCCESSFUL; - } - - the_mutex->nest_count--; + _CORE_mutex_Set_owner( the_mutex, new_owner ); - if ( the_mutex->nest_count != 0 ) { - /* - * All error checking is on the locking side, so if the lock was - * allowed to acquired multiple times, then we should just deal with - * that. The RTEMS_DEBUG is just a validation. - */ - #if defined(RTEMS_DEBUG) - switch ( the_mutex->Attributes.lock_nesting_behavior ) { - case CORE_MUTEX_NESTING_ACQUIRES: - _CORE_mutex_Release( the_mutex, queue_context ); - return STATUS_SUCCESSFUL; - #if defined(RTEMS_POSIX_API) - case CORE_MUTEX_NESTING_IS_ERROR: - /* should never occur */ - _CORE_mutex_Release( the_mutex, queue_context ); - return STATUS_NESTING_NOT_ALLOWED; - #endif - } - #else - _CORE_mutex_Release( the_mutex, queue_context ); - /* must be CORE_MUTEX_NESTING_ACQUIRES or we wouldn't be here */ - return STATUS_SUCCESSFUL; - #endif - } - - /* - * Formally release the mutex before possibly transferring it to a - * blocked thread. - */ - holder->resource_count--; - the_mutex->holder = NULL; - - /* - * Now we check if another thread was waiting for this mutex. If so, - * transfer the mutex to that thread. - */ - if ( - ( the_thread = _Thread_queue_First_locked( - &the_mutex->Wait_queue, - CORE_MUTEX_TQ_OPERATIONS - ) - ) - ) { - bool unblock; - - the_mutex->holder = the_thread; - the_mutex->nest_count = 1; - - /* - * We must extract the thread now since this will restore its default - * thread lock. This is necessary to avoid a deadlock in the - * _Thread_Change_priority() below due to a recursive thread queue lock - * acquire. - */ unblock = _Thread_queue_Extract_locked( &the_mutex->Wait_queue.Queue, - CORE_MUTEX_TQ_OPERATIONS, - the_thread, + operations, + new_owner, queue_context ); #if defined(RTEMS_MULTIPROCESSING) - if ( _Objects_Is_local_id( the_thread->Object.id ) ) + if ( _Objects_Is_local_id( new_owner->Object.id ) ) #endif { - the_thread->resource_count++; - _Thread_queue_Boost_priority( &the_mutex->Wait_queue.Queue, the_thread ); + ++new_owner->resource_count; + _Thread_queue_Boost_priority( &the_mutex->Wait_queue.Queue, new_owner ); } _Thread_queue_Unblock_critical( unblock, &the_mutex->Wait_queue.Queue, - the_thread, + new_owner, &queue_context->Lock_context ); } else { _CORE_mutex_Release( the_mutex, queue_context ); } - /* - * Whether or not someone is waiting for the mutex, an - * inherited priority must be lowered if this is the last - * mutex (i.e. resource) this task has. - */ - 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 ); - - if ( holder->priority_restore_hint ) { - Per_CPU_Control *cpu_self; + if ( !keep_priority ) { + Per_CPU_Control *cpu_self; - cpu_self = _Thread_Dispatch_disable(); - _Thread_Restore_priority( holder ); - _Thread_Dispatch_enable( cpu_self ); - } + cpu_self = _Thread_Dispatch_disable(); + _Thread_Restore_priority( executing ); + _Thread_Dispatch_enable( cpu_self ); } - _CORE_mutex_Restore_priority( holder ); return STATUS_SUCCESSFUL; } diff --git a/cpukit/score/src/debugisownerofallocator.c b/cpukit/score/src/debugisownerofallocator.c index 57da2ca001..6b396df4fc 100644 --- a/cpukit/score/src/debugisownerofallocator.c +++ b/cpukit/score/src/debugisownerofallocator.c @@ -27,7 +27,7 @@ bool owner; if ( mutex != NULL ) { - owner = mutex->Mutex.holder == _Thread_Get_executing(); + owner = _API_Mutex_Is_owner( mutex ); } else { owner = false; } |