From 03e8928753ef76cb747b965938092c59d6306060 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 27 Mar 2014 14:46:31 +0100 Subject: score: Delete CORE_mutex_Control::lock The holder field is enough to determine if a mutex is locked or not. This leads also to better error status codes in case a rtems_semaphore_release() is done for a mutex without having the ownership. --- cpukit/libmisc/monitor/mon-sema.c | 8 +++++--- cpukit/posix/src/mutexinit.c | 7 +------ cpukit/rtems/src/semcreate.c | 2 +- cpukit/score/include/rtems/score/coremutex.h | 3 --- cpukit/score/include/rtems/score/coremuteximpl.h | 20 +++++--------------- cpukit/score/src/apimutex.c | 2 +- cpukit/score/src/coremutex.c | 5 ++--- cpukit/score/src/coremutexsurrender.c | 3 +-- testsuites/sptests/sp51/init.c | 4 ++-- 9 files changed, 18 insertions(+), 36 deletions(-) diff --git a/cpukit/libmisc/monitor/mon-sema.c b/cpukit/libmisc/monitor/mon-sema.c index df474eafc7..10448663d9 100644 --- a/cpukit/libmisc/monitor/mon-sema.c +++ b/cpukit/libmisc/monitor/mon-sema.c @@ -35,15 +35,17 @@ rtems_monitor_sema_canonical( rtems_sema->Core_control.semaphore.Attributes.maximum_count; } else { + /* we have a binary semaphore (mutex) */ Thread_Control *holder = rtems_sema->Core_control.mutex.holder; if (holder != NULL) { canonical_sema->holder_id = holder->Object.id; + canonical_sema->cur_count = 0; + } else { + canonical_sema->cur_count = 1; } - /* we have a binary semaphore (mutex) */ - canonical_sema->cur_count = rtems_sema->Core_control.mutex.lock; - canonical_sema->max_count = 1; /* mutex is either 0 or 1 */ + canonical_sema->max_count = 1; /* mutex is either 0 or 1 */ } } diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c index 73d3101b28..fdaa6090ee 100644 --- a/cpukit/posix/src/mutexinit.c +++ b/cpukit/posix/src/mutexinit.c @@ -172,12 +172,7 @@ int pthread_mutex_init( /* * Must be initialized to unlocked. */ - _CORE_mutex_Initialize( - &the_mutex->Mutex, - NULL, - the_mutex_attr, - CORE_MUTEX_UNLOCKED - ); + _CORE_mutex_Initialize( &the_mutex->Mutex, NULL, the_mutex_attr, false ); _Objects_Open_u32( &_POSIX_Mutex_Information, &the_mutex->Object, 0 ); diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c index 5cd9568a46..fb597d1cbd 100644 --- a/cpukit/rtems/src/semcreate.c +++ b/cpukit/rtems/src/semcreate.c @@ -179,7 +179,7 @@ rtems_status_code rtems_semaphore_create( &the_semaphore->Core_control.mutex, _Thread_Get_executing(), &the_mutex_attr, - (count == 1) ? CORE_MUTEX_UNLOCKED : CORE_MUTEX_LOCKED + count != 1 ); if ( mutex_status == CORE_MUTEX_STATUS_CEILING_VIOLATED ) { diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h index a29aee5ac8..ccf6066740 100644 --- a/cpukit/score/include/rtems/score/coremutex.h +++ b/cpukit/score/include/rtems/score/coremutex.h @@ -155,9 +155,6 @@ typedef struct { * behavior. */ CORE_mutex_Attributes Attributes; - /** This element contains the current state of the mutex. - */ - uint32_t lock; /** This element contains the number of times the mutex has been acquired * nested. This must be zero (0) before the mutex is actually unlocked. */ diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h index 497843850f..cf327e81c3 100644 --- a/cpukit/score/include/rtems/score/coremuteximpl.h +++ b/cpukit/score/include/rtems/score/coremuteximpl.h @@ -98,16 +98,6 @@ typedef enum { */ #define CORE_MUTEX_STATUS_LAST CORE_MUTEX_STATUS_CEILING_VIOLATED -/** - * This is the value of a mutex when it is unlocked. - */ -#define CORE_MUTEX_UNLOCKED 1 - -/** - * This is the value of a mutex when it is locked. - */ -#define CORE_MUTEX_LOCKED 0 - /** * @brief Initializes the mutex based on the parameters passed. * @@ -117,7 +107,8 @@ typedef enum { * @param[in,out] executing The currently executing thread. * @param[in] the_mutex_attributes is the attributes associated with this * mutex instance - * @param[in] initial_lock is the initial value of the mutex + * @param[in] initially_locked If true, then the mutex is initially locked by + * the executing thread. * * @retval This method returns CORE_MUTEX_STATUS_SUCCESSFUL if successful. */ @@ -125,7 +116,7 @@ CORE_mutex_Status _CORE_mutex_Initialize( CORE_mutex_Control *the_mutex, Thread_Control *executing, const CORE_mutex_Attributes *the_mutex_attributes, - uint32_t initial_lock + bool initially_locked ); /** @@ -357,7 +348,7 @@ RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_locked( CORE_mutex_Control *the_mutex ) { - return the_mutex->lock == CORE_MUTEX_LOCKED; + return the_mutex->holder != NULL; } /** @@ -452,7 +443,6 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body( executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL; if ( !_CORE_mutex_Is_locked( the_mutex ) ) { - the_mutex->lock = CORE_MUTEX_LOCKED; the_mutex->holder = executing; the_mutex->nest_count = 1; if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) || @@ -499,7 +489,7 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body( } /* if ( current < ceiling ) */ { executing->Wait.return_code = CORE_MUTEX_STATUS_CEILING_VIOLATED; - the_mutex->lock = CORE_MUTEX_UNLOCKED; + the_mutex->holder = NULL; the_mutex->nest_count = 0; /* undo locking above */ executing->resource_count--; /* undo locking above */ _ISR_Enable( level ); diff --git a/cpukit/score/src/apimutex.c b/cpukit/score/src/apimutex.c index 7899934183..ec2fbdc3ec 100644 --- a/cpukit/score/src/apimutex.c +++ b/cpukit/score/src/apimutex.c @@ -61,7 +61,7 @@ void _API_Mutex_Allocate( mutex = (API_Mutex_Control *) _Objects_Allocate_unprotected( &_API_Mutex_Information ); - _CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, CORE_MUTEX_UNLOCKED ); + _CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, false ); _Objects_Open_u32( &_API_Mutex_Information, &mutex->Object, 1 ); diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c index 1c6c3db302..96b11c9cd1 100644 --- a/cpukit/score/src/coremutex.c +++ b/cpukit/score/src/coremutex.c @@ -27,7 +27,7 @@ CORE_mutex_Status _CORE_mutex_Initialize( CORE_mutex_Control *the_mutex, Thread_Control *executing, const CORE_mutex_Attributes *the_mutex_attributes, - uint32_t initial_lock + bool initially_locked ) { @@ -37,9 +37,8 @@ CORE_mutex_Status _CORE_mutex_Initialize( */ the_mutex->Attributes = *the_mutex_attributes; - the_mutex->lock = initial_lock; - if ( initial_lock == CORE_MUTEX_LOCKED ) { + if ( initially_locked ) { the_mutex->nest_count = 1; the_mutex->holder = executing; if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) || diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c index de1c744c2c..fff3cd74da 100644 --- a/cpukit/score/src/coremutexsurrender.c +++ b/cpukit/score/src/coremutexsurrender.c @@ -217,8 +217,7 @@ CORE_mutex_Status _CORE_mutex_Surrender( break; } } - } else - the_mutex->lock = CORE_MUTEX_UNLOCKED; + } return CORE_MUTEX_STATUS_SUCCESSFUL; } diff --git a/testsuites/sptests/sp51/init.c b/testsuites/sptests/sp51/init.c index fba2206ec3..98d362f89c 100644 --- a/testsuites/sptests/sp51/init.c +++ b/testsuites/sptests/sp51/init.c @@ -52,10 +52,10 @@ rtems_task Init( fatal_directive_status( sc, RTEMS_INVALID_PRIORITY, "rtems_semaphore_obtain" ); - /* This returns successful because RTEMS eats the unneeded unlock */ puts( "Release semaphore we did not obtain" ); sc = rtems_semaphore_release( mutex ); - directive_failed( sc, "rtems_semaphore_release" ); + fatal_directive_status( + sc, RTEMS_NOT_OWNER_OF_RESOURCE, "rtems_semaphore_release" ); TEST_END(); rtems_test_exit( 0 ); -- cgit v1.2.3