summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthreadonce.c
diff options
context:
space:
mode:
authorChristian Mauderer <Christian.Mauderer@embedded-brains.de>2014-03-20 09:22:00 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-21 11:21:49 +0100
commita5385b1f729cf671f458c0b2128a0d64b0c307a6 (patch)
treec32e522d68c4f3c5370b382631600afb5aa063e3 /cpukit/posix/src/pthreadonce.c
parentsmptests/smpload01: Improve test (diff)
downloadrtems-a5385b1f729cf671f458c0b2128a0d64b0c307a6.tar.bz2
score: Unify pthread and gxx_wrapper once and move to score.
Diffstat (limited to 'cpukit/posix/src/pthreadonce.c')
-rw-r--r--cpukit/posix/src/pthreadonce.c37
1 files changed, 2 insertions, 35 deletions
diff --git a/cpukit/posix/src/pthreadonce.c b/cpukit/posix/src/pthreadonce.c
index 87a3b53ef6..dc8a449a87 100644
--- a/cpukit/posix/src/pthreadonce.c
+++ b/cpukit/posix/src/pthreadonce.c
@@ -23,51 +23,18 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/score/apimutex.h>
-
-#define PTHREAD_ONCE_INIT_NOT_RUN 0
-#define PTHREAD_ONCE_INIT_RUNNING 1
-#define PTHREAD_ONCE_INIT_COMPLETE 2
+#include <rtems/score/onceimpl.h>
int pthread_once(
pthread_once_t *once_control,
void (*init_routine)(void)
)
{
- int r = 0;
-
if ( !once_control || !init_routine )
return EINVAL;
if ( once_control->is_initialized != 1 )
return EINVAL;
- if ( once_control->init_executed != PTHREAD_ONCE_INIT_COMPLETE ) {
- _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.
- */
-
- 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;
+ return _Once( &once_control->init_executed, init_routine );
}