diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-10-08 10:09:14 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-10-08 11:26:27 +0200 |
commit | dfdad6ab1d4a8f51acca0420de3188b5470f7f16 (patch) | |
tree | f17a273045e47ac6e51a7f68fcc7b6671ad91e01 | |
parent | posix: Use function instead of macros (diff) | |
download | rtems-dfdad6ab1d4a8f51acca0420de3188b5470f7f16.tar.bz2 |
posix: Fix mutex auto initialization
Use the once lock to prevent race conditions during auto initialization.
-rw-r--r-- | cpukit/posix/src/mutexget.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cpukit/posix/src/mutexget.c b/cpukit/posix/src/mutexget.c index f683137655..41a5495fa2 100644 --- a/cpukit/posix/src/mutexget.c +++ b/cpukit/posix/src/mutexget.c @@ -19,6 +19,7 @@ #endif #include <rtems/posix/muteximpl.h> +#include <rtems/score/apimutex.h> static bool _POSIX_Mutex_Check_id_and_auto_init( pthread_mutex_t *mutex, @@ -34,7 +35,15 @@ static bool _POSIX_Mutex_Check_id_and_auto_init( if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) { int eno; - eno = pthread_mutex_init( mutex, NULL ); + _Once_Lock(); + + if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) { + eno = pthread_mutex_init( mutex, NULL ); + } else { + eno = 0; + } + + _Once_Unlock(); if ( eno != 0 ) { *location = OBJECTS_ERROR; |