summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-09-21 15:42:45 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-05 14:29:02 +0200
commit89fc9345dea5c675f8d93546fa3c723918d3279a (patch)
tree89c32d64f375e1a9bf9d3725b1256aeb7ca46221 /cpukit/posix/src
parentposix: Implement self-contained POSIX barriers (diff)
downloadrtems-89fc9345dea5c675f8d93546fa3c723918d3279a.tar.bz2
posix: Implement self-contained POSIX rwlocks
POSIX rwlocks are now available in all configurations and no longer depend on --enable-posix. Update #2514. Update #3115.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/prwlock.c48
-rw-r--r--cpukit/posix/src/prwlockdestroy.c20
-rw-r--r--cpukit/posix/src/prwlockinit.c81
-rw-r--r--cpukit/posix/src/prwlockrdlock.c9
-rw-r--r--cpukit/posix/src/prwlocktimedrdlock.c9
-rw-r--r--cpukit/posix/src/prwlocktimedwrlock.c9
-rw-r--r--cpukit/posix/src/prwlocktryrdlock.c9
-rw-r--r--cpukit/posix/src/prwlocktrywrlock.c9
-rw-r--r--cpukit/posix/src/prwlockunlock.c26
-rw-r--r--cpukit/posix/src/prwlockwrlock.c11
10 files changed, 75 insertions, 156 deletions
diff --git a/cpukit/posix/src/prwlock.c b/cpukit/posix/src/prwlock.c
deleted file mode 100644
index f81d4e5bba..0000000000
--- a/cpukit/posix/src/prwlock.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * RWLock Manager -- Initialization
- *
- * COPYRIGHT (c) 1989-2008.
- * On-Line Applications Research Corporation (OAR).
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <limits.h>
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/sysinit.h>
-#include <rtems/posix/rwlockimpl.h>
-
-Objects_Information _POSIX_RWLock_Information;
-
-/**
- * @brief _POSIX_RWLock_Manager_initialization
- */
-
-static void _POSIX_RWLock_Manager_initialization(void)
-{
- _Objects_Initialize_information(
- &_POSIX_RWLock_Information, /* object information table */
- OBJECTS_POSIX_API, /* object API */
- OBJECTS_POSIX_RWLOCKS, /* object class */
- Configuration_POSIX_API.maximum_rwlocks,
- /* maximum objects of this class */
- sizeof( POSIX_RWLock_Control ), /* size of this object's control block */
- true, /* true if the name is a string */
- _POSIX_PATH_MAX, /* maximum length of each object's name */
- NULL /* Proxy extraction support callout */
- );
-}
-
-RTEMS_SYSINIT_ITEM(
- _POSIX_RWLock_Manager_initialization,
- RTEMS_SYSINIT_POSIX_RWLOCK,
- RTEMS_SYSINIT_ORDER_MIDDLE
-);
diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c
index 0ced556146..49fd630ecd 100644
--- a/cpukit/posix/src/prwlockdestroy.c
+++ b/cpukit/posix/src/prwlockdestroy.c
@@ -20,29 +20,23 @@
#include <rtems/posix/rwlockimpl.h>
int pthread_rwlock_destroy(
- pthread_rwlock_t *rwlock
+ pthread_rwlock_t *_rwlock
)
{
POSIX_RWLock_Control *the_rwlock;
Thread_queue_Context queue_context;
- _Objects_Allocator_lock();
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
+ the_rwlock = _POSIX_RWLock_Get( _rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
- if ( the_rwlock == NULL ) {
- _Objects_Allocator_unlock();
- return EINVAL;
- }
-
- _CORE_RWLock_Acquire_critical( &the_rwlock->RWLock, &queue_context );
+ _CORE_RWLock_Acquire( &the_rwlock->RWLock, &queue_context );
/*
* If there is at least one thread waiting, then do not delete it.
*/
- if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Wait_queue.Queue ) ) {
+ if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Queue.Queue ) ) {
_CORE_RWLock_Release( &the_rwlock->RWLock, &queue_context );
- _Objects_Allocator_unlock();
return EBUSY;
}
@@ -50,9 +44,7 @@ int pthread_rwlock_destroy(
* POSIX doesn't require behavior when it is locked.
*/
- _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
+ the_rwlock->flags = ~the_rwlock->flags;
_CORE_RWLock_Release( &the_rwlock->RWLock, &queue_context );
- _POSIX_RWLock_Free( the_rwlock );
- _Objects_Allocator_unlock();
return 0;
}
diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
index ffce8149a9..a5e2ba1f54 100644
--- a/cpukit/posix/src/prwlockinit.c
+++ b/cpukit/posix/src/prwlockinit.c
@@ -23,35 +23,34 @@
#include <rtems/posix/rwlockimpl.h>
#include <rtems/posix/posixapi.h>
-POSIX_RWLock_Control *_POSIX_RWLock_Get(
- pthread_rwlock_t *rwlock,
- Thread_queue_Context *queue_context
-)
-{
- _POSIX_Get_object_body(
- POSIX_RWLock_Control,
- rwlock,
- queue_context,
- &_POSIX_RWLock_Information,
- PTHREAD_RWLOCK_INITIALIZER,
- pthread_rwlock_init
- );
-}
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_RWLock_Control, flags )
+ == offsetof( pthread_rwlock_t, _flags ),
+ POSIX_RWLOCK_CONTROL_FLAGS
+);
-/*
- * pthread_rwlock_init
- *
- * This directive creates a rwlock. A rwlock id is returned.
- *
- * Input parameters:
- * rwlock - pointer to rwlock id
- * attr - rwlock attributes
- *
- * Output parameters:
- * rwlock - rwlock id
- * 0 - if successful
- * error code - if unsuccessful
- */
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_RWLock_Control, RWLock.current_state )
+ == offsetof( pthread_rwlock_t, _current_state ),
+ POSIX_RWLOCK_CONTROL_CURRENT_STATE
+);
+
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_RWLock_Control, RWLock.number_of_readers )
+ == offsetof( pthread_rwlock_t, _number_of_readers ),
+ POSIX_RWLOCK_CONTROL_NUMBER_OF_READERS
+);
+
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_RWLock_Control, RWLock.Queue )
+ == offsetof( pthread_rwlock_t, _Queue ),
+ POSIX_RWLOCK_CONTROL_QUEUE
+);
+
+RTEMS_STATIC_ASSERT(
+ sizeof( POSIX_RWLock_Control ) == sizeof( pthread_rwlock_t ),
+ POSIX_RWLOCK_CONTROL_SIZE
+);
int pthread_rwlock_init(
pthread_rwlock_t *rwlock,
@@ -60,11 +59,11 @@ int pthread_rwlock_init(
{
POSIX_RWLock_Control *the_rwlock;
- /*
- * Error check parameters
- */
- if ( !rwlock )
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+
+ if ( the_rwlock == NULL ) {
return EINVAL;
+ }
if ( attr != NULL ) {
if ( !attr->is_initialized ) {
@@ -76,23 +75,7 @@ int pthread_rwlock_init(
}
}
- the_rwlock = _POSIX_RWLock_Allocate();
-
- if ( !the_rwlock ) {
- _Objects_Allocator_unlock();
- return EAGAIN;
- }
-
+ the_rwlock->flags = (uintptr_t) the_rwlock ^ POSIX_RWLOCK_MAGIC;
_CORE_RWLock_Initialize( &the_rwlock->RWLock );
-
- _Objects_Open_u32(
- &_POSIX_RWLock_Information,
- &the_rwlock->Object,
- 0
- );
-
- *rwlock = the_rwlock->Object.id;
-
- _Objects_Allocator_unlock();
return 0;
}
diff --git a/cpukit/posix/src/prwlockrdlock.c b/cpukit/posix/src/prwlockrdlock.c
index 5b15f5568f..4019c1fcb2 100644
--- a/cpukit/posix/src/prwlockrdlock.c
+++ b/cpukit/posix/src/prwlockrdlock.c
@@ -29,16 +29,13 @@ int pthread_rwlock_rdlock(
Thread_queue_Context queue_context;
Status_Control status;
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+ _Thread_queue_Context_initialize( &queue_context );
_Thread_queue_Context_set_no_timeout( &queue_context );
status = _CORE_RWLock_Seize_for_reading(
&the_rwlock->RWLock,
- _Thread_Executing,
true, /* we are willing to wait forever */
&queue_context
);
diff --git a/cpukit/posix/src/prwlocktimedrdlock.c b/cpukit/posix/src/prwlocktimedrdlock.c
index 623453073e..a9ac13348d 100644
--- a/cpukit/posix/src/prwlocktimedrdlock.c
+++ b/cpukit/posix/src/prwlocktimedrdlock.c
@@ -50,16 +50,13 @@ int pthread_rwlock_timedrdlock(
timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+ _Thread_queue_Context_initialize( &queue_context );
_Thread_queue_Context_set_relative_timeout( &queue_context, ticks );
status = _CORE_RWLock_Seize_for_reading(
&the_rwlock->RWLock,
- _Thread_Executing,
do_wait,
&queue_context
);
diff --git a/cpukit/posix/src/prwlocktimedwrlock.c b/cpukit/posix/src/prwlocktimedwrlock.c
index 1fd57c0106..1f1e654d53 100644
--- a/cpukit/posix/src/prwlocktimedwrlock.c
+++ b/cpukit/posix/src/prwlocktimedwrlock.c
@@ -52,16 +52,13 @@ int pthread_rwlock_timedwrlock(
timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+ _Thread_queue_Context_initialize( &queue_context );
_Thread_queue_Context_set_relative_timeout( &queue_context, ticks );
status = _CORE_RWLock_Seize_for_writing(
&the_rwlock->RWLock,
- _Thread_Executing,
do_wait,
&queue_context
);
diff --git a/cpukit/posix/src/prwlocktryrdlock.c b/cpukit/posix/src/prwlocktryrdlock.c
index 052f1b011e..e934d286ae 100644
--- a/cpukit/posix/src/prwlocktryrdlock.c
+++ b/cpukit/posix/src/prwlocktryrdlock.c
@@ -29,15 +29,12 @@ int pthread_rwlock_tryrdlock(
Thread_queue_Context queue_context;
Status_Control status;
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+ _Thread_queue_Context_initialize( &queue_context );
status = _CORE_RWLock_Seize_for_reading(
&the_rwlock->RWLock,
- _Thread_Executing,
false, /* do not wait for the rwlock */
&queue_context
);
diff --git a/cpukit/posix/src/prwlocktrywrlock.c b/cpukit/posix/src/prwlocktrywrlock.c
index 976e7a84ac..ccbeb3114b 100644
--- a/cpukit/posix/src/prwlocktrywrlock.c
+++ b/cpukit/posix/src/prwlocktrywrlock.c
@@ -29,15 +29,12 @@ int pthread_rwlock_trywrlock(
Thread_queue_Context queue_context;
Status_Control status;
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+ _Thread_queue_Context_initialize( &queue_context );
status = _CORE_RWLock_Seize_for_writing(
&the_rwlock->RWLock,
- _Thread_Executing,
false, /* we are not willing to wait */
&queue_context
);
diff --git a/cpukit/posix/src/prwlockunlock.c b/cpukit/posix/src/prwlockunlock.c
index 05be366c23..92cc0bfde2 100644
--- a/cpukit/posix/src/prwlockunlock.c
+++ b/cpukit/posix/src/prwlockunlock.c
@@ -23,20 +23,32 @@
#include <rtems/posix/rwlockimpl.h>
#include <rtems/posix/posixapi.h>
+#include <string.h>
+
+bool _POSIX_RWLock_Auto_initialization( POSIX_RWLock_Control *the_rwlock )
+{
+ POSIX_RWLock_Control zero;
+
+ memset( &zero, 0, sizeof( zero ) );
+
+ if ( memcmp( the_rwlock, &zero, sizeof( *the_rwlock ) ) != 0 ) {
+ return false;
+ }
+
+ the_rwlock->flags = POSIX_RWLOCK_MAGIC;
+ return true;
+}
+
int pthread_rwlock_unlock(
pthread_rwlock_t *rwlock
)
{
POSIX_RWLock_Control *the_rwlock;
- Thread_queue_Context queue_context;
Status_Control status;
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
- status = _CORE_RWLock_Surrender( &the_rwlock->RWLock, &queue_context );
+ status = _CORE_RWLock_Surrender( &the_rwlock->RWLock );
return _POSIX_Get_error( status );
}
diff --git a/cpukit/posix/src/prwlockwrlock.c b/cpukit/posix/src/prwlockwrlock.c
index a78554f878..df4d2685aa 100644
--- a/cpukit/posix/src/prwlockwrlock.c
+++ b/cpukit/posix/src/prwlockwrlock.c
@@ -23,8 +23,6 @@
#include <rtems/posix/rwlockimpl.h>
#include <rtems/posix/posixapi.h>
-THREAD_QUEUE_OBJECT_ASSERT( POSIX_RWLock_Control, RWLock.Wait_queue );
-
int pthread_rwlock_wrlock(
pthread_rwlock_t *rwlock
)
@@ -33,16 +31,13 @@ int pthread_rwlock_wrlock(
Thread_queue_Context queue_context;
Status_Control status;
- the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
-
- if ( the_rwlock == NULL ) {
- return EINVAL;
- }
+ the_rwlock = _POSIX_RWLock_Get( rwlock );
+ POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+ _Thread_queue_Context_initialize( &queue_context );
_Thread_queue_Context_set_no_timeout( &queue_context );
status = _CORE_RWLock_Seize_for_writing(
&the_rwlock->RWLock,
- _Thread_Executing,
true, /* do not timeout -- wait forever */
&queue_context
);