diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-20 06:43:11 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-22 09:25:08 +0200 |
commit | 2dd5e6fb320a5309e02570fad93d4b5fc09328a7 (patch) | |
tree | 0600823693f0c6d2e521537622d2ac89809765a0 /cpukit/posix/src | |
parent | score: Avoid Giant lock for CORE mtx/sem (diff) | |
download | rtems-2dd5e6fb320a5309e02570fad93d4b5fc09328a7.tar.bz2 |
posix: Use _Objects_Get_local() for semaphores
This simplifies the code since the object location is no longer used.
Remove superfluous header includes.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r-- | cpukit/posix/src/semaphorewaitsupp.c | 60 | ||||
-rw-r--r-- | cpukit/posix/src/semclose.c | 40 | ||||
-rw-r--r-- | cpukit/posix/src/semdestroy.c | 51 | ||||
-rw-r--r-- | cpukit/posix/src/semgetvalue.c | 45 | ||||
-rw-r--r-- | cpukit/posix/src/sempost.c | 44 |
5 files changed, 79 insertions, 161 deletions
diff --git a/cpukit/posix/src/semaphorewaitsupp.c b/cpukit/posix/src/semaphorewaitsupp.c index cf8fe63c93..84ebe3d9e2 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 1468c7fb35..3f18ff1efe 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 751169941b..5264472156 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 f89526610f..63e3823dff 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 8e8cce9251..13c0132abd 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; } |