diff options
Diffstat (limited to '')
-rw-r--r-- | cpukit/rtems/include/rtems/rtems/semimpl.h | 1 | ||||
-rw-r--r-- | cpukit/rtems/src/semcreate.c | 43 | ||||
-rw-r--r-- | cpukit/rtems/src/semdelete.c | 19 | ||||
-rw-r--r-- | cpukit/rtems/src/semflush.c | 5 | ||||
-rw-r--r-- | cpukit/rtems/src/semobtain.c | 5 | ||||
-rw-r--r-- | cpukit/rtems/src/semrelease.c | 13 |
6 files changed, 53 insertions, 33 deletions
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 <rtems/rtems/semimpl.h> -#include <rtems/rtems/attrimpl.h> #include <rtems/rtems/statusimpl.h> 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( |