diff options
author | Chris Johns <chrisj@rtems.org> | 2013-08-14 10:21:41 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2013-08-14 10:21:41 +1000 |
commit | 03acc5915e002f0b03eee9e86212209705cca6d6 (patch) | |
tree | 93c452a3f546f0d6f4456481c78e9fc6d4a6e082 /cpukit/posix/src/once.c | |
parent | posix: Handle recursive attributes correctly. (diff) | |
download | rtems-03acc5915e002f0b03eee9e86212209705cca6d6.tar.bz2 |
posix: Change pthread_once to be SMP safe.
Change pthread_once from using disabled pre-emption to using a
pthread mutex making it SMP safe. GCC using a posix threading
model uses pthread_once.
The pthread mutex requires at least 1 mutex is configured so
confdefs.h has been updated to account for the internal
mutex.
Diffstat (limited to 'cpukit/posix/src/once.c')
-rw-r--r-- | cpukit/posix/src/once.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cpukit/posix/src/once.c b/cpukit/posix/src/once.c new file mode 100644 index 0000000000..d77c3c12e3 --- /dev/null +++ b/cpukit/posix/src/once.c @@ -0,0 +1,49 @@ +/** + * @file + * + * @brief POSIX Once Manager Initialization + * @ingroup POSIX_ONCE POSIX Once Support + */ + +/* + * COPYRIGHT (c) 2013 + * Chris Johns <chrisj@rtems.org> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <pthread.h> +#include <errno.h> + +#include <rtems.h> +#include <rtems/posix/onceimpl.h> + +pthread_mutex_t _POSIX_Once_Lock; + +void _POSIX_Once_Manager_initialization(void) +{ + pthread_mutexattr_t mattr; + int r; + + _POSIX_Once_Lock = PTHREAD_MUTEX_INITIALIZER; + + r = pthread_mutexattr_init( &mattr ); + if ( r != 0 ) + rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa0000 | r ); + + r = pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_RECURSIVE ); + if ( r != 0 ) + rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa1000 | r ); + + r = pthread_mutex_init( &_POSIX_Once_Lock, &mattr ); + if ( r != 0 ) + rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa2000 | r ); + + pthread_mutexattr_destroy( &mattr ); +} |