mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-23 03:56:16 +08:00
posix: Add auto initializaton for rwlock
This commit is contained in:
@@ -92,28 +92,10 @@ RTEMS_INLINE_ROUTINE void _POSIX_RWLock_Free (
|
||||
_Objects_Free( &_POSIX_RWLock_Information, &the_RWLock->Object );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a RWLock control block.
|
||||
*
|
||||
* This function maps RWLock IDs to RWLock control blocks.
|
||||
* If ID corresponds to a local RWLock, then it returns
|
||||
* the_RWLock control pointer which maps to ID and location
|
||||
* is set to OBJECTS_LOCAL. if the RWLock ID is global and
|
||||
* resides on a remote node, then location is set to OBJECTS_REMOTE,
|
||||
* and the_RWLock is undefined. Otherwise, location is set
|
||||
* to OBJECTS_ERROR and the_RWLock is undefined.
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Get (
|
||||
pthread_rwlock_t *RWLock,
|
||||
POSIX_RWLock_Control *_POSIX_RWLock_Get(
|
||||
pthread_rwlock_t *rwlock,
|
||||
Objects_Locations *location
|
||||
)
|
||||
{
|
||||
return (POSIX_RWLock_Control *) _Objects_Get(
|
||||
&_POSIX_RWLock_Information,
|
||||
(Objects_Id) *RWLock,
|
||||
location
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -41,9 +41,6 @@ int pthread_rwlock_destroy(
|
||||
POSIX_RWLock_Control *the_rwlock = NULL;
|
||||
Objects_Locations location;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
_Objects_Allocator_lock();
|
||||
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
|
||||
switch ( location ) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -41,9 +41,6 @@ int pthread_rwlock_rdlock(
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
|
||||
switch ( location ) {
|
||||
|
||||
|
||||
@@ -50,9 +50,6 @@ int pthread_rwlock_timedrdlock(
|
||||
POSIX_Absolute_timeout_conversion_results_t status;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* POSIX requires that blocking calls with timeouts that take
|
||||
* an absolute timeout must ignore issues with the absolute
|
||||
|
||||
@@ -52,9 +52,6 @@ int pthread_rwlock_timedwrlock(
|
||||
POSIX_Absolute_timeout_conversion_results_t status;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* POSIX requires that blocking calls with timeouts that take
|
||||
* an absolute timeout must ignore issues with the absolute
|
||||
|
||||
@@ -45,9 +45,6 @@ int pthread_rwlock_tryrdlock(
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
|
||||
switch ( location ) {
|
||||
|
||||
|
||||
@@ -45,9 +45,6 @@ int pthread_rwlock_trywrlock(
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
|
||||
switch ( location ) {
|
||||
|
||||
|
||||
@@ -47,9 +47,6 @@ int pthread_rwlock_unlock(
|
||||
Objects_Locations location;
|
||||
CORE_RWLock_Status status;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
|
||||
switch ( location ) {
|
||||
|
||||
|
||||
@@ -47,9 +47,6 @@ int pthread_rwlock_wrlock(
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
|
||||
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
|
||||
switch ( location ) {
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ int main(
|
||||
#endif
|
||||
{
|
||||
pthread_rwlock_t rwlock;
|
||||
pthread_rwlock_t rwlock2;
|
||||
pthread_rwlockattr_t attr;
|
||||
int status;
|
||||
int p;
|
||||
@@ -153,6 +154,42 @@ int main(
|
||||
status = pthread_rwlockattr_setpshared( &attr, ~PTHREAD_PROCESS_PRIVATE );
|
||||
rtems_test_assert( status == EINVAL );
|
||||
|
||||
/*************** AUTO INITIALIZATION *****************/
|
||||
|
||||
rwlock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
rwlock2 = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
status = pthread_rwlock_rdlock( &rwlock );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
status = pthread_rwlock_rdlock( &rwlock2 );
|
||||
rtems_test_assert( status == EINVAL );
|
||||
|
||||
status = pthread_rwlock_destroy( &rwlock );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
status = pthread_rwlock_rdlock( &rwlock2 );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
status = pthread_rwlock_destroy( &rwlock );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
rwlock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
rwlock2 = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
status = pthread_rwlock_rdlock( &rwlock );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
status = pthread_rwlock_destroy( &rwlock2 );
|
||||
rtems_test_assert( status == EINVAL );
|
||||
|
||||
status = pthread_rwlock_destroy( &rwlock );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
status = pthread_rwlock_destroy( &rwlock2 );
|
||||
rtems_test_assert( status == 0 );
|
||||
rtems_test_assert( rwlock2 != PTHREAD_RWLOCK_INITIALIZER );
|
||||
|
||||
/*************** ACTUALLY WORK THIS TIME *****************/
|
||||
puts( "pthread_rwlockattr_init( &attr ) -- OK" );
|
||||
status = pthread_rwlockattr_init( &attr );
|
||||
|
||||
Reference in New Issue
Block a user