summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthreadonce.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-18 08:28:14 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-19 08:34:26 +0100
commit51f823c9327e3e73fb75688aaeeefae35007f37c (patch)
tree40798813bed67cc4fe27f7e570834fea9aa76276 /cpukit/posix/src/pthreadonce.c
parentscore: Make _ISR_Enable_without_giant() available (diff)
downloadrtems-51f823c9327e3e73fb75688aaeeefae35007f37c.tar.bz2
posix: Use interal mutex for once implementation
Enable pthread_once() for all configurations. The pthread_once() function is one means to initialize POSIX keys. Another use case is the C++ support.
Diffstat (limited to 'cpukit/posix/src/pthreadonce.c')
-rw-r--r--cpukit/posix/src/pthreadonce.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/cpukit/posix/src/pthreadonce.c b/cpukit/posix/src/pthreadonce.c
index aa8afe7bf4..6b8274d60e 100644
--- a/cpukit/posix/src/pthreadonce.c
+++ b/cpukit/posix/src/pthreadonce.c
@@ -23,9 +23,7 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems.h>
-#include <rtems/system.h>
-#include <rtems/posix/onceimpl.h>
+#include <rtems/score/apimutex.h>
#define PTHREAD_ONCE_INIT_NOT_RUN 0
#define PTHREAD_ONCE_INIT_RUNNING 1
@@ -45,34 +43,30 @@ int pthread_once(
return EINVAL;
if ( once_control->init_executed != PTHREAD_ONCE_INIT_COMPLETE ) {
- r = pthread_mutex_lock( &_POSIX_Once_Lock );
- if ( r == 0 ) {
- int rr;
+ _Once_Lock();
- /*
- * Getting to here means the once_control is locked so we have:
- * 1. The init has not run and the state is PTHREAD_ONCE_INIT_NOT_RUN.
- * 2. The init has finished and the state is PTHREAD_ONCE_INIT_RUN.
- * 3. The init is being run by this thread and the state
- * PTHREAD_ONCE_INIT_RUNNING so we are nesting. This is an error.
- */
+ /*
+ * Getting to here means the once_control is locked so we have:
+ * 1. The init has not run and the state is PTHREAD_ONCE_INIT_NOT_RUN.
+ * 2. The init has finished and the state is PTHREAD_ONCE_INIT_RUN.
+ * 3. The init is being run by this thread and the state
+ * PTHREAD_ONCE_INIT_RUNNING so we are nesting. This is an error.
+ */
- switch ( once_control->init_executed ) {
- case PTHREAD_ONCE_INIT_NOT_RUN:
- once_control->init_executed = PTHREAD_ONCE_INIT_RUNNING;
- (*init_routine)();
- once_control->init_executed = PTHREAD_ONCE_INIT_COMPLETE;
- break;
- case PTHREAD_ONCE_INIT_RUNNING:
- r = EINVAL;
- break;
- default:
- break;
- }
- rr = pthread_mutex_unlock( &_POSIX_Once_Lock );
- if ( r == 0 )
- r = rr;
+ switch ( once_control->init_executed ) {
+ case PTHREAD_ONCE_INIT_NOT_RUN:
+ once_control->init_executed = PTHREAD_ONCE_INIT_RUNNING;
+ (*init_routine)();
+ once_control->init_executed = PTHREAD_ONCE_INIT_COMPLETE;
+ break;
+ case PTHREAD_ONCE_INIT_RUNNING:
+ r = EINVAL;
+ break;
+ default:
+ break;
}
+
+ _Once_Unlock();
}
return r;