diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-22 14:37:13 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-27 08:50:41 +0200 |
commit | 7f4ee2b4ae39928ab5f449048e562ef6b2c5d17d (patch) | |
tree | ec62caff9b95826169b43cc8a8e66b24fa861015 /cpukit/posix/src/condget.c | |
parent | telnetd: Fix warnings (diff) | |
download | rtems-7f4ee2b4ae39928ab5f449048e562ef6b2c5d17d.tar.bz2 |
posix: Avoid Giant lock for condition variables
Update #2555.
Diffstat (limited to 'cpukit/posix/src/condget.c')
-rw-r--r-- | cpukit/posix/src/condget.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/cpukit/posix/src/condget.c b/cpukit/posix/src/condget.c index 6ebba730a3..e3cf59c4a5 100644 --- a/cpukit/posix/src/condget.c +++ b/cpukit/posix/src/condget.c @@ -11,45 +11,49 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - -#include <rtems/system.h> -#include <rtems/score/watchdog.h> #include <rtems/posix/condimpl.h> -#include <rtems/posix/muteximpl.h> -POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get ( - pthread_cond_t *cond, - Objects_Locations *location +static bool _POSIX_Condition_variables_Check_id_and_auto_init( + pthread_cond_t *cond ) { - int status; - - if ( !cond ) { - *location = OBJECTS_ERROR; - return (POSIX_Condition_variables_Control *) 0; + if ( cond == NULL ) { + return false; } if ( *cond == PTHREAD_COND_INITIALIZER ) { - /* - * Do an "auto-create" here. - */ - - status = pthread_cond_init( cond, 0 ); - if ( status ) { - *location = OBJECTS_ERROR; - return (POSIX_Condition_variables_Control *) 0; + int eno; + + _Once_Lock(); + + if ( *cond == PTHREAD_COND_INITIALIZER ) { + eno = pthread_cond_init( cond, NULL ); + } else { + eno = 0; + } + + _Once_Unlock(); + + if ( eno != 0 ) { + return false; } } - /* - * Now call Objects_Get() - */ - return (POSIX_Condition_variables_Control *)_Objects_Get( - &_POSIX_Condition_variables_Information, + return true; +} + +POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get( + pthread_cond_t *cond, + ISR_lock_Context *lock_context +) +{ + if ( !_POSIX_Condition_variables_Check_id_and_auto_init( cond ) ) { + return NULL; + } + + return (POSIX_Condition_variables_Control *) _Objects_Get_local( (Objects_Id) *cond, - location + &_POSIX_Condition_variables_Information, + lock_context ); } - |