From 89fc9345dea5c675f8d93546fa3c723918d3279a Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 21 Sep 2017 15:42:45 +0200 Subject: 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. --- cpukit/posix/Makefile.am | 11 +--- cpukit/posix/include/rtems/posix/config.h | 6 -- cpukit/posix/include/rtems/posix/rwlock.h | 63 --------------------- cpukit/posix/include/rtems/posix/rwlockimpl.h | 54 +++++++----------- cpukit/posix/preinstall.am | 12 ++-- cpukit/posix/src/prwlock.c | 48 ---------------- cpukit/posix/src/prwlockdestroy.c | 20 ++----- cpukit/posix/src/prwlockinit.c | 81 +++++++++++---------------- cpukit/posix/src/prwlockrdlock.c | 9 +-- cpukit/posix/src/prwlocktimedrdlock.c | 9 +-- cpukit/posix/src/prwlocktimedwrlock.c | 9 +-- cpukit/posix/src/prwlocktryrdlock.c | 9 +-- cpukit/posix/src/prwlocktrywrlock.c | 9 +-- cpukit/posix/src/prwlockunlock.c | 26 ++++++--- cpukit/posix/src/prwlockwrlock.c | 11 +--- 15 files changed, 103 insertions(+), 274 deletions(-) delete mode 100644 cpukit/posix/include/rtems/posix/rwlock.h delete mode 100644 cpukit/posix/src/prwlock.c (limited to 'cpukit/posix') diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am index 7980ca3cc5..b69ca23132 100644 --- a/cpukit/posix/Makefile.am +++ b/cpukit/posix/Makefile.am @@ -22,6 +22,7 @@ include_rtems_posix_HEADERS += include/rtems/posix/keyimpl.h include_rtems_posix_HEADERS += include/rtems/posix/config.h include_rtems_posix_HEADERS += include/rtems/posix/posixapi.h include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h +include_rtems_posix_HEADERS += include/rtems/posix/rwlockimpl.h include_rtems_posix_HEADERS += include/rtems/posix/semaphore.h include_rtems_posix_HEADERS += include/rtems/posix/semaphoreimpl.h include_rtems_posix_HEADERS += include/rtems/posix/spinlockimpl.h @@ -50,8 +51,6 @@ include_rtems_posix_HEADERS += include/rtems/posix/shmimpl.h include_rtems_posix_HEADERS += include/rtems/posix/threadsup.h include_rtems_posix_HEADERS += include/rtems/posix/timer.h include_rtems_posix_HEADERS += include/rtems/posix/timerimpl.h -include_rtems_posix_HEADERS += include/rtems/posix/rwlock.h -include_rtems_posix_HEADERS += include/rtems/posix/rwlockimpl.h ## src libposix_a_SOURCES += src/aio_cancel.c src/aio_error.c src/aio_fsync.c \ @@ -194,18 +193,14 @@ libposix_a_SOURCES += src/semtimedwait.c libposix_a_SOURCES += src/semtrywait.c libposix_a_SOURCES += src/semwait.c -if HAS_PTHREADS -libposix_a_SOURCES += src/sigpending.c \ - src/sigqueue.c src/sigsuspend.c src/sigtimedwait.c \ - src/sigwait.c src/sigwaitinfo.c src/signal_2.c src/ualarm.c - ## RWLOCK_C_FILES -libposix_a_SOURCES += src/prwlock.c src/prwlockdestroy.c src/prwlockinit.c \ +libposix_a_SOURCES += src/prwlockdestroy.c src/prwlockinit.c \ src/prwlockrdlock.c src/prwlocktimedrdlock.c src/prwlocktimedwrlock.c \ src/prwlocktryrdlock.c src/prwlocktrywrlock.c src/prwlockunlock.c \ src/prwlockwrlock.c src/rwlockattrdestroy.c src/rwlockattrgetpshared.c \ src/rwlockattrinit.c src/rwlockattrsetpshared.c +if HAS_PTHREADS ## SEMAPHORE_C_FILES libposix_a_SOURCES += src/semaphore.c libposix_a_SOURCES += src/semaphoredeletesupp.c diff --git a/cpukit/posix/include/rtems/posix/config.h b/cpukit/posix/include/rtems/posix/config.h index dc1ef0c2f1..799eb62f03 100644 --- a/cpukit/posix/include/rtems/posix/config.h +++ b/cpukit/posix/include/rtems/posix/config.h @@ -98,12 +98,6 @@ typedef struct { */ uint32_t maximum_semaphores; - /** - * This field contains the maximum number of POSIX API - * read/write locks which are configured for this application. - */ - uint32_t maximum_rwlocks; - /** * Maximum configured number of POSIX Shared memory objects. */ diff --git a/cpukit/posix/include/rtems/posix/rwlock.h b/cpukit/posix/include/rtems/posix/rwlock.h deleted file mode 100644 index 3d33d40915..0000000000 --- a/cpukit/posix/include/rtems/posix/rwlock.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @file - * - * @brief Constants and Structures Associated with the POSIX RWLock Manager - * - * This include file contains all the constants and structures associated - * with the POSIX RWLock Manager. - * - * Directives provided are: - * - * - create a RWLock - * - delete a RWLock - * - wait for a RWLock - */ - -/* - * COPYRIGHT (c) 1989-2011. - * 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. - */ - -#ifndef _RTEMS_POSIX_RWLOCK_H -#define _RTEMS_POSIX_RWLOCK_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup POSIX_RWLOCK POSIX RWLock Manager - * - * @ingroup POSIXAPI - * - * @brief Constants and Structures Associated with the POSIX RWLock Manager - * - */ -/**@{**/ - -/** - * This type defines the control block used to manage each RWLock. - */ - -typedef struct { - /** This is used to manage a RWLock as an object. */ - Objects_Control Object; - /** This is used to implement the RWLock. */ - CORE_RWLock_Control RWLock; -} POSIX_RWLock_Control; - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif -/* end of include file */ diff --git a/cpukit/posix/include/rtems/posix/rwlockimpl.h b/cpukit/posix/include/rtems/posix/rwlockimpl.h index c355f7dc19..b92ca9d04c 100644 --- a/cpukit/posix/include/rtems/posix/rwlockimpl.h +++ b/cpukit/posix/include/rtems/posix/rwlockimpl.h @@ -19,9 +19,7 @@ #ifndef _RTEMS_POSIX_RWLOCKIMPL_H #define _RTEMS_POSIX_RWLOCKIMPL_H -#include #include -#include #include #include @@ -30,43 +28,33 @@ extern "C" { #endif -/** - * The following defines the information control block used to manage - * this class of objects. - */ - -extern Objects_Information _POSIX_RWLock_Information; +#define POSIX_RWLOCK_MAGIC 0x9621dabdUL -/** - * @brief Allocate a RWLock control block. - * - * This function allocates a RWLock control block from - * the inactive chain of free RWLock control blocks. - */ -RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Allocate( void ) -{ - return (POSIX_RWLock_Control *) - _Objects_Allocate( &_POSIX_RWLock_Information ); -} +typedef struct { + unsigned long flags; + CORE_RWLock_Control RWLock; +} POSIX_RWLock_Control; -/** - * @brief Free a RWLock control block. - * - * This routine frees a RWLock control block to the - * inactive chain of free RWLock control blocks. - */ -RTEMS_INLINE_ROUTINE void _POSIX_RWLock_Free ( - POSIX_RWLock_Control *the_RWLock +RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Get( + pthread_rwlock_t *rwlock ) { - _CORE_RWLock_Destroy( &the_RWLock->RWLock ); - _Objects_Free( &_POSIX_RWLock_Information, &the_RWLock->Object ); + return (POSIX_RWLock_Control *) rwlock; } -POSIX_RWLock_Control *_POSIX_RWLock_Get( - pthread_rwlock_t *rwlock, - Thread_queue_Context *queue_context -); +bool _POSIX_RWLock_Auto_initialization( POSIX_RWLock_Control *the_rwlock ); + +#define POSIX_RWLOCK_VALIDATE_OBJECT( rw ) \ + do { \ + if ( ( rw ) == NULL ) { \ + return EINVAL; \ + } \ + if ( ( (uintptr_t) ( rw ) ^ POSIX_RWLOCK_MAGIC ) != ( rw )->flags ) { \ + if ( !_POSIX_RWLock_Auto_initialization( rw ) ) { \ + return EINVAL; \ + } \ + } \ + } while ( 0 ) #ifdef __cplusplus } diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am index 903591ad65..45d1c465b5 100644 --- a/cpukit/posix/preinstall.am +++ b/cpukit/posix/preinstall.am @@ -51,6 +51,10 @@ $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: include/rtems/posix/priorityimpl. $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h +$(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h: include/rtems/posix/rwlockimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h + $(PROJECT_INCLUDE)/rtems/posix/semaphore.h: include/rtems/posix/semaphore.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/semaphore.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/semaphore.h @@ -143,14 +147,6 @@ PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timer.h $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h: include/rtems/posix/timerimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h - -$(PROJECT_INCLUDE)/rtems/posix/rwlock.h: include/rtems/posix/rwlock.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlock.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlock.h - -$(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h: include/rtems/posix/rwlockimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h endif if HAS_PTHREADS endif 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 - -#include -#include -#include -#include - -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 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 #include -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 #include +#include + +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 #include -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 ); -- cgit v1.2.3