summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/prwlockinit.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-10-08 10:31:36 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-10-08 11:26:27 +0200
commitb9f952254b7f9afeb287ab6d846a56a512a480d3 (patch)
tree67d466d323a07abad18465bbfa1572097bb645ab /cpukit/posix/src/prwlockinit.c
parentposix: Fix mutex auto initialization (diff)
downloadrtems-b9f952254b7f9afeb287ab6d846a56a512a480d3.tar.bz2
posix: Add auto initializaton for rwlock
Diffstat (limited to 'cpukit/posix/src/prwlockinit.c')
-rw-r--r--cpukit/posix/src/prwlockinit.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
index 94973f6b78..7cf781ff2a 100644
--- a/cpukit/posix/src/prwlockinit.c
+++ b/cpukit/posix/src/prwlockinit.c
@@ -23,8 +23,58 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/system.h>
#include <rtems/posix/rwlockimpl.h>
+#include <rtems/score/apimutex.h>
+
+static bool _POSIX_RWLock_Check_id_and_auto_init(
+ pthread_mutex_t *rwlock,
+ Objects_Locations *location
+)
+{
+ if ( rwlock == NULL ) {
+ *location = OBJECTS_ERROR;
+
+ return false;
+ }
+
+ if ( *rwlock == PTHREAD_RWLOCK_INITIALIZER ) {
+ int eno;
+
+ _Once_Lock();
+
+ if ( *rwlock == PTHREAD_RWLOCK_INITIALIZER ) {
+ eno = pthread_rwlock_init( rwlock, NULL );
+ } else {
+ eno = 0;
+ }
+
+ _Once_Unlock();
+
+ if ( eno != 0 ) {
+ *location = OBJECTS_ERROR;
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
+POSIX_RWLock_Control *_POSIX_RWLock_Get(
+ pthread_rwlock_t *rwlock,
+ Objects_Locations *location
+)
+{
+ if ( !_POSIX_RWLock_Check_id_and_auto_init( rwlock, location ) ) {
+ return NULL;
+ }
+
+ return (POSIX_RWLock_Control *) _Objects_Get(
+ &_POSIX_RWLock_Information,
+ *rwlock,
+ location
+ );
+}
/*
* pthread_rwlock_init