diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-20 14:01:02 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-22 09:25:09 +0200 |
commit | f27383a518836881b7b9b88e88d2e31d5b23d048 (patch) | |
tree | ecdccfa9c902a5a8db0918026e8074af0b581a6a /cpukit/posix/src | |
parent | score: Add _Thread_queue_Flush_default_filter() (diff) | |
download | rtems-f27383a518836881b7b9b88e88d2e31d5b23d048.tar.bz2 |
score: Avoid Giant lock for barriers
Use _Thread_queue_Flush_critical() to atomically release the barrier.
Update #2555.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r-- | cpukit/posix/src/pbarrierdestroy.c | 45 | ||||
-rw-r--r-- | cpukit/posix/src/pbarrierwait.c | 50 |
2 files changed, 39 insertions, 56 deletions
diff --git a/cpukit/posix/src/pbarrierdestroy.c b/cpukit/posix/src/pbarrierdestroy.c index 4b9a0fdca9..709644bf4e 100644 --- a/cpukit/posix/src/pbarrierdestroy.c +++ b/cpukit/posix/src/pbarrierdestroy.c @@ -18,10 +18,6 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - -#include <rtems/system.h> #include <rtems/posix/barrierimpl.h> /** @@ -39,37 +35,32 @@ int pthread_barrier_destroy( pthread_barrier_t *barrier ) { - POSIX_Barrier_Control *the_barrier = NULL; - Objects_Locations location; + POSIX_Barrier_Control *the_barrier; + ISR_lock_Context lock_context; - if ( !barrier ) + if ( barrier == NULL ) { return EINVAL; + } _Objects_Allocator_lock(); - the_barrier = _POSIX_Barrier_Get( barrier, &location ); - switch ( location ) { + the_barrier = _POSIX_Barrier_Get( barrier, &lock_context ); - case OBJECTS_LOCAL: - if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) { - _Objects_Put( &the_barrier->Object ); - return EBUSY; - } - - _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object ); - _Objects_Put( &the_barrier->Object ); + if ( the_barrier == NULL ) { + _Objects_Allocator_unlock(); + return EINVAL; + } - _POSIX_Barrier_Free( the_barrier ); - _Objects_Allocator_unlock(); - return 0; + _CORE_barrier_Acquire_critical( &the_barrier->Barrier, &lock_context ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) { + _CORE_barrier_Release( &the_barrier->Barrier, &lock_context ); + _Objects_Allocator_unlock(); + return EBUSY; } + _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object ); + _CORE_barrier_Release( &the_barrier->Barrier, &lock_context ); + _POSIX_Barrier_Free( the_barrier ); _Objects_Allocator_unlock(); - - return EINVAL; + return 0; } diff --git a/cpukit/posix/src/pbarrierwait.c b/cpukit/posix/src/pbarrierwait.c index 86bfba7b09..9200dc0eee 100644 --- a/cpukit/posix/src/pbarrierwait.c +++ b/cpukit/posix/src/pbarrierwait.c @@ -18,9 +18,6 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/barrierimpl.h> #include <rtems/score/threadimpl.h> @@ -40,36 +37,31 @@ int pthread_barrier_wait( pthread_barrier_t *barrier ) { - POSIX_Barrier_Control *the_barrier = NULL; - Objects_Locations location; - Thread_Control *executing; + POSIX_Barrier_Control *the_barrier; + ISR_lock_Context lock_context; + Thread_Control *executing; - if ( !barrier ) + if ( barrier == NULL ) { return EINVAL; + } - the_barrier = _POSIX_Barrier_Get( barrier, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - executing = _Thread_Executing; - _CORE_barrier_Seize( - &the_barrier->Barrier, - executing, - true, - 0, - NULL, - 0 - ); - _Objects_Put( &the_barrier->Object ); - return _POSIX_Barrier_Translate_core_barrier_return_code( - executing->Wait.return_code ); + the_barrier = _POSIX_Barrier_Get( barrier, &lock_context ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_barrier == NULL ) { + return EINVAL; } - return EINVAL; + executing = _Thread_Executing; + _CORE_barrier_Seize( + &the_barrier->Barrier, + executing, + true, + 0, + NULL, + 0, + &lock_context + ); + return _POSIX_Barrier_Translate_core_barrier_return_code( + executing->Wait.return_code + ); } |