This simplifies the code since the object location is no longer used. Remove superfluous header includes. --- cpukit/posix/include/rtems/posix/semaphoreimpl.h | 11 ++--- cpukit/posix/src/semaphorewaitsupp.c | 60 +++++++++--------------- cpukit/posix/src/semclose.c | 40 ++++++---------- cpukit/posix/src/semdestroy.c | 51 ++++++++------------ cpukit/posix/src/semgetvalue.c | 45 +++++------------- cpukit/posix/src/sempost.c | 44 +++++------------ 6 files changed, 83 insertions(+), 168 deletions(-)
diff --git a/cpukit/posix/include/rtems/posix/semaphoreimpl.h b/cpukit/posix/include/rtems/posix/semaphoreimpl.h index d726761..6ec8480 100644 --- a/cpukit/posix/include/rtems/posix/semaphoreimpl.h +++ b/cpukit/posix/include/rtems/posix/semaphoreimpl.h @@ -60,17 +60,14 @@ RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free ( _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object ); } -RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control * -_POSIX_Semaphore_Get_interrupt_disable( - sem_t *id, - Objects_Locations *location, +RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get( + const sem_t *id, ISR_lock_Context *lock_context ) { - return (POSIX_Semaphore_Control *) _Objects_Get_isr_disable( + return (POSIX_Semaphore_Control *) _Objects_Get_local( + (Objects_Id) *id, &_POSIX_Semaphore_Information, - (Objects_Id)*id, - location, lock_context ); } diff --git a/cpukit/posix/src/semaphorewaitsupp.c b/cpukit/posix/src/semaphorewaitsupp.c index cf8fe63..84ebe3d 100644 --- a/cpukit/posix/src/semaphorewaitsupp.c +++ b/cpukit/posix/src/semaphorewaitsupp.c @@ -18,18 +18,10 @@ #include "config.h" #endif -#include <stdarg.h> - -#include <errno.h> -#include <fcntl.h> -#include <pthread.h> #include <semaphore.h> -#include <limits.h> -#include <rtems/system.h> -#include <rtems/score/threadimpl.h> #include <rtems/posix/semaphoreimpl.h> -#include <rtems/seterr.h> +#include <rtems/score/threadimpl.h> THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_Semaphore_Control, @@ -43,43 +35,33 @@ int _POSIX_Semaphore_Wait_support( ) { POSIX_Semaphore_Control *the_semaphore; - Objects_Locations location; Thread_Control *executing; ISR_lock_Context lock_context; - the_semaphore = _POSIX_Semaphore_Get_interrupt_disable( - sem, - &location, - &lock_context - ); - switch ( location ) { + the_semaphore = _POSIX_Semaphore_Get( sem, &lock_context ); - case OBJECTS_LOCAL: - executing = _Thread_Executing; - _CORE_semaphore_Seize( - &the_semaphore->Semaphore, - executing, - the_semaphore->Object.id, - blocking, - timeout, - &lock_context - ); + if ( the_semaphore == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } - if ( !executing->Wait.return_code ) - return 0; + executing = _Thread_Executing; - rtems_set_errno_and_return_minus_one( - _POSIX_Semaphore_Translate_core_semaphore_return_code( - executing->Wait.return_code - ) - ); + _CORE_semaphore_Seize( + &the_semaphore->Semaphore, + executing, + the_semaphore->Object.id, + blocking, + timeout, + &lock_context + ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( executing->Wait.return_code == CORE_SEMAPHORE_STATUS_SUCCESSFUL ) { + return 0; } - rtems_set_errno_and_return_minus_one( EINVAL ); + rtems_set_errno_and_return_minus_one( + _POSIX_Semaphore_Translate_core_semaphore_return_code( + executing->Wait.return_code + ) + ); } diff --git a/cpukit/posix/src/semclose.c b/cpukit/posix/src/semclose.c index 1468c7f..3f18ff1 100644 --- a/cpukit/posix/src/semclose.c +++ b/cpukit/posix/src/semclose.c @@ -26,36 +26,24 @@ int sem_close( sem_t *sem ) { - POSIX_Semaphore_Control *the_semaphore; - Objects_Locations location; - ISR_lock_Context lock_context; + POSIX_Semaphore_Control *the_semaphore; + ISR_lock_Context lock_context; _Objects_Allocator_lock(); - the_semaphore = _POSIX_Semaphore_Get_interrupt_disable( - sem, - &location, + the_semaphore = _POSIX_Semaphore_Get( sem, &lock_context ); + + if ( the_semaphore == NULL ) { + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + _CORE_semaphore_Acquire_critical( + &the_semaphore->Semaphore, &lock_context ); - switch ( location ) { - - case OBJECTS_LOCAL: - _CORE_semaphore_Acquire_critical( - &the_semaphore->Semaphore, - &lock_context - ); - the_semaphore->open_count -= 1; - _POSIX_Semaphore_Delete( the_semaphore, &lock_context ); - _Objects_Allocator_unlock(); - return 0; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; - } + the_semaphore->open_count -= 1; + _POSIX_Semaphore_Delete( the_semaphore, &lock_context ); _Objects_Allocator_unlock(); - - rtems_set_errno_and_return_minus_one( EINVAL ); + return 0; } diff --git a/cpukit/posix/src/semdestroy.c b/cpukit/posix/src/semdestroy.c index 7511699..5264472 100644 --- a/cpukit/posix/src/semdestroy.c +++ b/cpukit/posix/src/semdestroy.c @@ -26,44 +26,31 @@ int sem_destroy( sem_t *sem ) { - POSIX_Semaphore_Control *the_semaphore; - Objects_Locations location; - ISR_lock_Context lock_context; + POSIX_Semaphore_Control *the_semaphore; + ISR_lock_Context lock_context; _Objects_Allocator_lock(); - the_semaphore = _POSIX_Semaphore_Get_interrupt_disable( - sem, - &location, - &lock_context - ); - switch ( location ) { + the_semaphore = _POSIX_Semaphore_Get( sem, &lock_context ); - case OBJECTS_LOCAL: - _CORE_semaphore_Acquire_critical( - &the_semaphore->Semaphore, - &lock_context - ); + if ( the_semaphore == NULL ) { + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EINVAL ); + } - /* - * Undefined operation on a named semaphore. Release the object - * and fall to the EINVAL return at the bottom. - */ - if ( the_semaphore->named ) { - _CORE_semaphore_Release( &the_semaphore->Semaphore, &lock_context ); - } else { - _POSIX_Semaphore_Delete( the_semaphore, &lock_context ); - _Objects_Allocator_unlock(); - return 0; - } + _CORE_semaphore_Acquire_critical( + &the_semaphore->Semaphore, + &lock_context + ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_semaphore->named ) { + /* Undefined operation on a named semaphore */ + _CORE_semaphore_Release( &the_semaphore->Semaphore, &lock_context ); + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EINVAL ); } - _Objects_Allocator_unlock(); + _POSIX_Semaphore_Delete( the_semaphore, &lock_context ); - rtems_set_errno_and_return_minus_one( EINVAL ); + _Objects_Allocator_unlock(); + return 0; } diff --git a/cpukit/posix/src/semgetvalue.c b/cpukit/posix/src/semgetvalue.c index f895266..63e3823 100644 --- a/cpukit/posix/src/semgetvalue.c +++ b/cpukit/posix/src/semgetvalue.c @@ -18,49 +18,30 @@ #include "config.h" #endif -#include <stdarg.h> - -#include <errno.h> -#include <fcntl.h> -#include <pthread.h> #include <semaphore.h> -#include <limits.h> -#include <rtems/system.h> #include <rtems/posix/semaphoreimpl.h> -#include <rtems/seterr.h> int sem_getvalue( sem_t *__restrict sem, int *__restrict sval ) { - POSIX_Semaphore_Control *the_semaphore; - Objects_Locations location; - ISR_lock_Context lock_context; - - the_semaphore = _POSIX_Semaphore_Get_interrupt_disable( - sem, - &location, - &lock_context - ); - switch ( location ) { + POSIX_Semaphore_Control *the_semaphore; + ISR_lock_Context lock_context; - case OBJECTS_LOCAL: - /* - * Assume a relaxed atomic load of the value on SMP configurations. - * Thus, there is no need to acquire a lock. - */ - *sval = _CORE_semaphore_Get_count( &the_semaphore->Semaphore ); - _ISR_lock_ISR_enable( &lock_context ); - return 0; + the_semaphore = _POSIX_Semaphore_Get( sem, &lock_context ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_semaphore == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); } - rtems_set_errno_and_return_minus_one( EINVAL ); + /* + * Assume a relaxed atomic load of the value on SMP configurations. + * Thus, there is no need to acquire a lock. + */ + *sval = _CORE_semaphore_Get_count( &the_semaphore->Semaphore ); + + _ISR_lock_ISR_enable( &lock_context ); + return 0; } diff --git a/cpukit/posix/src/sempost.c b/cpukit/posix/src/sempost.c index 8e8cce9..13c0132 100644 --- a/cpukit/posix/src/sempost.c +++ b/cpukit/posix/src/sempost.c @@ -18,48 +18,28 @@ #include "config.h" #endif -#include <stdarg.h> - -#include <errno.h> -#include <fcntl.h> -#include <pthread.h> #include <semaphore.h> -#include <limits.h> -#include <rtems/system.h> #include <rtems/posix/semaphoreimpl.h> -#include <rtems/seterr.h> int sem_post( sem_t *sem ) { - POSIX_Semaphore_Control *the_semaphore; - Objects_Locations location; - ISR_lock_Context lock_context; - - the_semaphore = _POSIX_Semaphore_Get_interrupt_disable( - sem, - &location, - &lock_context - ); - switch ( location ) { + POSIX_Semaphore_Control *the_semaphore; + ISR_lock_Context lock_context; - case OBJECTS_LOCAL: - _CORE_semaphore_Surrender( - &the_semaphore->Semaphore, - NULL, - 0, - &lock_context - ); - return 0; + the_semaphore = _POSIX_Semaphore_Get( sem, &lock_context ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_semaphore == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); } - rtems_set_errno_and_return_minus_one( EINVAL ); + _CORE_semaphore_Surrender( + &the_semaphore->Semaphore, + NULL, + 0, + &lock_context + ); + return 0; } -- 1.8.4.5 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel