From 09c5ca4cb4f30ba9e0c3c3915a70af7ff3916ec0 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 26 May 2016 22:29:56 +0200 Subject: score: Simplify CORE mutex Remove superfluous support for simple binary semaphores. With this we can get rid of the CORE_MUTEX_NESTING_BLOCKS variant. --- cpukit/rtems/include/rtems/rtems/semimpl.h | 1 + cpukit/rtems/src/semcreate.c | 43 ++++++++++++------------ cpukit/rtems/src/semdelete.c | 19 +++++------ cpukit/rtems/src/semflush.c | 5 ++- cpukit/rtems/src/semobtain.c | 5 ++- cpukit/rtems/src/semrelease.c | 13 +++++++ cpukit/score/include/rtems/score/coremutex.h | 7 ---- cpukit/score/include/rtems/score/coremuteximpl.h | 2 -- cpukit/score/src/coremutexsurrender.c | 3 -- 9 files changed, 53 insertions(+), 45 deletions(-) (limited to 'cpukit') diff --git a/cpukit/rtems/include/rtems/rtems/semimpl.h b/cpukit/rtems/include/rtems/rtems/semimpl.h index 813f885d5f..f3dfa0213a 100644 --- a/cpukit/rtems/include/rtems/rtems/semimpl.h +++ b/cpukit/rtems/include/rtems/rtems/semimpl.h @@ -28,6 +28,7 @@ extern "C" { typedef enum { SEMAPHORE_VARIANT_MUTEX, + SEMAPHORE_VARIANT_SIMPLE_BINARY, SEMAPHORE_VARIANT_COUNTING #if defined(RTEMS_SMP) , diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c index be8f9f5d3b..455182bd90 100644 --- a/cpukit/rtems/src/semcreate.c +++ b/cpukit/rtems/src/semcreate.c @@ -143,9 +143,6 @@ rtems_status_code rtems_semaphore_create( the_semaphore->discipline = SEMAPHORE_DISCIPLINE_FIFO; } - /* - * Initialize it as a counting semaphore. - */ if ( _Attributes_Is_counting_semaphore( attribute_set ) ) { the_semaphore->variant = SEMAPHORE_VARIANT_COUNTING; _CORE_semaphore_Initialize( @@ -153,6 +150,13 @@ rtems_status_code rtems_semaphore_create( count ); status = STATUS_SUCCESSFUL; + } else if ( _Attributes_Is_simple_binary_semaphore( attribute_set ) ) { + the_semaphore->variant = SEMAPHORE_VARIANT_SIMPLE_BINARY; + _CORE_semaphore_Initialize( + &the_semaphore->Core_control.semaphore, + count != 0 + ); + status = STATUS_SUCCESSFUL; #if defined(RTEMS_SMP) } else if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) { the_semaphore->variant = SEMAPHORE_VARIANT_MRSP; @@ -166,6 +170,8 @@ rtems_status_code rtems_semaphore_create( } else { the_semaphore->variant = SEMAPHORE_VARIANT_MUTEX; + _Assert( _Attributes_Is_binary_semaphore( attribute_set ) ); + /* * It is either simple binary semaphore or a more powerful mutex * style binary semaphore. This is the mutex style. @@ -175,25 +181,20 @@ rtems_status_code rtems_semaphore_create( else the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_FIFO; - if ( _Attributes_Is_binary_semaphore( attribute_set ) ) { - the_mutex_attr.priority_ceiling = _RTEMS_tasks_Priority_to_Core( - priority_ceiling - ); - the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES; - the_mutex_attr.only_owner_release = false; - - if ( the_mutex_attr.discipline == CORE_MUTEX_DISCIPLINES_PRIORITY ) { - if ( _Attributes_Is_inherit_priority( attribute_set ) ) { - the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; - the_mutex_attr.only_owner_release = true; - } else if ( _Attributes_Is_priority_ceiling( attribute_set ) ) { - the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; - the_mutex_attr.only_owner_release = true; - } + the_mutex_attr.priority_ceiling = _RTEMS_tasks_Priority_to_Core( + priority_ceiling + ); + the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES; + the_mutex_attr.only_owner_release = false; + + if ( the_mutex_attr.discipline == CORE_MUTEX_DISCIPLINES_PRIORITY ) { + if ( _Attributes_Is_inherit_priority( attribute_set ) ) { + the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; + the_mutex_attr.only_owner_release = true; + } else if ( _Attributes_Is_priority_ceiling( attribute_set ) ) { + the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; + the_mutex_attr.only_owner_release = true; } - } else /* must be simple binary semaphore */ { - the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_BLOCKS; - the_mutex_attr.only_owner_release = false; } status = _CORE_mutex_Initialize( diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c index 45c356f452..908c178593 100644 --- a/cpukit/rtems/src/semdelete.c +++ b/cpukit/rtems/src/semdelete.c @@ -19,7 +19,6 @@ #endif #include -#include #include rtems_status_code rtems_semaphore_delete( @@ -28,7 +27,6 @@ rtems_status_code rtems_semaphore_delete( { Semaphore_Control *the_semaphore; Thread_queue_Context queue_context; - rtems_attribute attribute_set; Status_Control status; _Objects_Allocator_lock(); @@ -46,8 +44,6 @@ rtems_status_code rtems_semaphore_delete( return RTEMS_INVALID_ID; } - attribute_set = the_semaphore->attribute_set; - _Thread_queue_Acquire_critical( &the_semaphore->Core_control.Wait_queue, &queue_context.Lock_context @@ -55,10 +51,7 @@ rtems_status_code rtems_semaphore_delete( switch ( the_semaphore->variant ) { case SEMAPHORE_VARIANT_MUTEX: - if ( - _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) - && !_Attributes_Is_simple_binary_semaphore( attribute_set ) - ) { + if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) ) { status = STATUS_RESOURCE_IN_USE; } else { status = STATUS_SUCCESSFUL; @@ -71,7 +64,10 @@ rtems_status_code rtems_semaphore_delete( break; #endif default: - _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING ); + _Assert( + the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY + || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING + ); status = STATUS_SUCCESSFUL; break; } @@ -102,7 +98,10 @@ rtems_status_code rtems_semaphore_delete( break; #endif default: - _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING ); + _Assert( + the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY + || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING + ); _CORE_semaphore_Destroy( &the_semaphore->Core_control.semaphore, _Semaphore_Get_operations( the_semaphore ), diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c index f768bbd4a7..2410ed2386 100644 --- a/cpukit/rtems/src/semflush.c +++ b/cpukit/rtems/src/semflush.c @@ -63,7 +63,10 @@ rtems_status_code rtems_semaphore_flush( rtems_id id ) ); break; default: - _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING ); + _Assert( + the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY + || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING + ); _CORE_semaphore_Flush( &the_semaphore->Core_control.semaphore, _Semaphore_Get_operations( the_semaphore ), diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c index 93591b87c6..5eebfa14b2 100644 --- a/cpukit/rtems/src/semobtain.c +++ b/cpukit/rtems/src/semobtain.c @@ -91,7 +91,10 @@ rtems_status_code rtems_semaphore_obtain( ); break; default: - _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING ); + _Assert( + the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY + || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING + ); status = _CORE_semaphore_Seize( &the_semaphore->Core_control.semaphore, _Semaphore_Get_operations( the_semaphore ), diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c index d18901a40c..3e13334e87 100644 --- a/cpukit/rtems/src/semrelease.c +++ b/cpukit/rtems/src/semrelease.c @@ -61,6 +61,19 @@ rtems_status_code rtems_semaphore_release( rtems_id id ) &queue_context ); break; + case SEMAPHORE_VARIANT_SIMPLE_BINARY: + status = _CORE_semaphore_Surrender( + &the_semaphore->Core_control.semaphore, + _Semaphore_Get_operations( the_semaphore ), + 1, + &queue_context + ); + _Assert( + status == STATUS_SUCCESSFUL + || status == STATUS_MAXIMUM_COUNT_EXCEEDED + ); + status = STATUS_SUCCESSFUL; + break; default: _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING ); status = _CORE_semaphore_Surrender( diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h index 41f1c4f22d..f8694095ac 100644 --- a/cpukit/score/include/rtems/score/coremutex.h +++ b/cpukit/score/include/rtems/score/coremutex.h @@ -87,13 +87,6 @@ typedef enum { */ CORE_MUTEX_NESTING_IS_ERROR, #endif - /** - * This sequence performs as indicated: - * + lock(m) - * + lock(m) - deadlocks or timeouts - * + unlock(m) - releases - */ - CORE_MUTEX_NESTING_BLOCKS } CORE_mutex_Nesting_behaviors; /** diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h index e29d4b7f5d..ccc414827d 100644 --- a/cpukit/score/include/rtems/score/coremuteximpl.h +++ b/cpukit/score/include/rtems/score/coremuteximpl.h @@ -238,8 +238,6 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_mutex_Seize_interrupt_trylock( _CORE_mutex_Release( the_mutex, queue_context ); return STATUS_NESTING_NOT_ALLOWED; #endif - case CORE_MUTEX_NESTING_BLOCKS: - break; } } diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c index 1da98276bf..6047409085 100644 --- a/cpukit/score/src/coremutexsurrender.c +++ b/cpukit/score/src/coremutexsurrender.c @@ -76,9 +76,6 @@ Status_Control _CORE_mutex_Surrender( _CORE_mutex_Release( the_mutex, queue_context ); return STATUS_NESTING_NOT_ALLOWED; #endif - case CORE_MUTEX_NESTING_BLOCKS: - /* Currently no API exercises this behavior. */ - break; } #else _CORE_mutex_Release( the_mutex, queue_context ); -- cgit v1.2.3