diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-21 06:32:16 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-22 09:25:09 +0200 |
commit | 84a539885335c629100a6a12b57ead54bbbc0165 (patch) | |
tree | ff8d0acd9624e3888dc7fc6df9003a98a19b9b3d /cpukit/posix/src | |
parent | score: Avoid Giant lock for barriers (diff) | |
download | rtems-84a539885335c629100a6a12b57ead54bbbc0165.tar.bz2 |
score: Avoid Giant lock for CORE rwlock
Update #2555.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r-- | cpukit/posix/src/prwlockdestroy.c | 72 | ||||
-rw-r--r-- | cpukit/posix/src/prwlockinit.c | 22 | ||||
-rw-r--r-- | cpukit/posix/src/prwlockrdlock.c | 56 | ||||
-rw-r--r-- | cpukit/posix/src/prwlocktimedrdlock.c | 88 | ||||
-rw-r--r-- | cpukit/posix/src/prwlocktimedwrlock.c | 87 | ||||
-rw-r--r-- | cpukit/posix/src/prwlocktryrdlock.c | 61 | ||||
-rw-r--r-- | cpukit/posix/src/prwlocktrywrlock.c | 60 | ||||
-rw-r--r-- | cpukit/posix/src/prwlockunlock.c | 41 | ||||
-rw-r--r-- | cpukit/posix/src/prwlockwrlock.c | 56 |
9 files changed, 174 insertions, 369 deletions
diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c index a675b90757..6f9eec8a1d 100644 --- a/cpukit/posix/src/prwlockdestroy.c +++ b/cpukit/posix/src/prwlockdestroy.c @@ -17,68 +17,42 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/rwlockimpl.h> -#include <rtems/score/threadqimpl.h> -/** - * This directive allows a thread to delete a rwlock specified by - * the rwlock id. The rwlock is freed back to the inactive - * rwlock chain. - * - * @param[in] rwlock is the rwlock id - * - * @return This method returns 0 if there was not an - * error. Otherwise, a status code is returned indicating the - * source of the error. - */ int pthread_rwlock_destroy( pthread_rwlock_t *rwlock ) { - POSIX_RWLock_Control *the_rwlock = NULL; - Objects_Locations location; + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; _Objects_Allocator_lock(); - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - case OBJECTS_LOCAL: - /* - * If there is at least one thread waiting, then do not delete it. - */ - if ( - _Thread_queue_First( - &the_rwlock->RWLock.Wait_queue, - CORE_RWLOCK_TQ_OPERATIONS - ) != NULL - ) { - _Objects_Put( &the_rwlock->Object ); - _Objects_Allocator_unlock(); - return EBUSY; - } - - /* - * POSIX doesn't require behavior when it is locked. - */ + if ( the_rwlock == NULL ) { + _Objects_Allocator_unlock(); + return EINVAL; + } - _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object ); - _Objects_Put( &the_rwlock->Object ); - _POSIX_RWLock_Free( the_rwlock ); - _Objects_Allocator_unlock(); + _CORE_RWLock_Acquire_critical( &the_rwlock->RWLock, &lock_context ); - return 0; + /* + * If there is at least one thread waiting, then do not delete it. + */ -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Wait_queue.Queue ) ) { + _CORE_RWLock_Release( &the_rwlock->RWLock, &lock_context ); + _Objects_Allocator_unlock(); + return EBUSY; } - _Objects_Allocator_unlock(); + /* + * POSIX doesn't require behavior when it is locked. + */ - return EINVAL; + _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object ); + _CORE_RWLock_Release( &the_rwlock->RWLock, &lock_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 afb70563e0..8bbb2fda8f 100644 --- a/cpukit/posix/src/prwlockinit.c +++ b/cpukit/posix/src/prwlockinit.c @@ -20,20 +20,14 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.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 + pthread_mutex_t *rwlock ) { if ( rwlock == NULL ) { - *location = OBJECTS_ERROR; - return false; } @@ -51,8 +45,6 @@ static bool _POSIX_RWLock_Check_id_and_auto_init( _Once_Unlock(); if ( eno != 0 ) { - *location = OBJECTS_ERROR; - return false; } } @@ -61,18 +53,18 @@ static bool _POSIX_RWLock_Check_id_and_auto_init( } POSIX_RWLock_Control *_POSIX_RWLock_Get( - pthread_rwlock_t *rwlock, - Objects_Locations *location + pthread_rwlock_t *rwlock, + ISR_lock_Context *lock_context ) { - if ( !_POSIX_RWLock_Check_id_and_auto_init( rwlock, location ) ) { + if ( !_POSIX_RWLock_Check_id_and_auto_init( rwlock ) ) { return NULL; } - return (POSIX_RWLock_Control *) _Objects_Get( - &_POSIX_RWLock_Information, + return (POSIX_RWLock_Control *) _Objects_Get_local( *rwlock, - location + &_POSIX_RWLock_Information, + lock_context ); } diff --git a/cpukit/posix/src/prwlockrdlock.c b/cpukit/posix/src/prwlockrdlock.c index 7d1bcaa9f4..3459399c6b 100644 --- a/cpukit/posix/src/prwlockrdlock.c +++ b/cpukit/posix/src/prwlockrdlock.c @@ -18,53 +18,31 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/rwlockimpl.h> -#include <rtems/score/thread.h> - -/** - * This directive attempts to obtain a read only lock on an rwlock instance. - * - * @param[in] rwlock is the pointer to rwlock id - * - * @retval 0 if successful - * @retval error_code if unsuccessful - */ int pthread_rwlock_rdlock( pthread_rwlock_t *rwlock ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - Thread_Control *executing; - - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + Thread_Control *executing; - executing = _Thread_Executing; - _CORE_RWLock_Seize_for_reading( - &the_rwlock->RWLock, - executing, - true, /* we are willing to wait forever */ - 0 - ); + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - _Objects_Put( &the_rwlock->Object ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( - (CORE_RWLock_Status) executing->Wait.return_code - ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_rwlock == NULL ) { + return EINVAL; } - return EINVAL; + executing = _Thread_Executing; + _CORE_RWLock_Seize_for_reading( + &the_rwlock->RWLock, + executing, + true, /* we are willing to wait forever */ + 0, + &lock_context + ); + return _POSIX_RWLock_Translate_core_RWLock_return_code( + (CORE_RWLock_Status) executing->Wait.return_code + ); } diff --git a/cpukit/posix/src/prwlocktimedrdlock.c b/cpukit/posix/src/prwlocktimedrdlock.c index 0f2878b581..829e1696a3 100644 --- a/cpukit/posix/src/prwlocktimedrdlock.c +++ b/cpukit/posix/src/prwlocktimedrdlock.c @@ -18,37 +18,20 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/rwlockimpl.h> -#include <rtems/score/thread.h> #include <rtems/score/todimpl.h> -/* - * pthread_rwlock_timedrdlock - * - * This directive attempts to obtain a read only lock on an rwlock instance. - * - * Input parameters: - * rwlock - pointer to rwlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ - int pthread_rwlock_timedrdlock( pthread_rwlock_t *rwlock, const struct timespec *abstime ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - Watchdog_Interval ticks; - bool do_wait = true; + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + Watchdog_Interval ticks; + bool do_wait; TOD_Absolute_timeout_conversion_results status; - Thread_Control *executing; + Thread_Control *executing; /* * POSIX requires that blocking calls with timeouts that take @@ -64,43 +47,40 @@ int pthread_rwlock_timedrdlock( * then we should not wait. */ status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks ); - if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE ) - do_wait = false; - - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { + do_wait = ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE ); - case OBJECTS_LOCAL: + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - executing = _Thread_Executing; - _CORE_RWLock_Seize_for_reading( - &the_rwlock->RWLock, - executing, - do_wait, - ticks - ); + if ( the_rwlock == NULL ) { + return EINVAL; + } - _Objects_Put( &the_rwlock->Object ); - if ( !do_wait ) { - if ( executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) { - if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID ) - return EINVAL; - if ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST || - status == TOD_ABSOLUTE_TIMEOUT_IS_NOW ) - return ETIMEDOUT; - } - } + executing = _Thread_Executing; + _CORE_RWLock_Seize_for_reading( + &the_rwlock->RWLock, + executing, + do_wait, + ticks, + &lock_context + ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( - (CORE_RWLock_Status) executing->Wait.return_code - ); + if ( + !do_wait + && ( executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) + ) { + if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID ) { + return EINVAL; + } -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( + status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST + || status == TOD_ABSOLUTE_TIMEOUT_IS_NOW + ) { + return ETIMEDOUT; + } } - return EINVAL; + return _POSIX_RWLock_Translate_core_RWLock_return_code( + (CORE_RWLock_Status) executing->Wait.return_code + ); } diff --git a/cpukit/posix/src/prwlocktimedwrlock.c b/cpukit/posix/src/prwlocktimedwrlock.c index 51558de5f8..1258c2bebb 100644 --- a/cpukit/posix/src/prwlocktimedwrlock.c +++ b/cpukit/posix/src/prwlocktimedwrlock.c @@ -20,37 +20,20 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/rwlockimpl.h> -#include <rtems/score/thread.h> #include <rtems/score/todimpl.h> -/* - * pthread_rwlock_timedwrlock - * - * This directive attempts to obtain a write only lock on an rwlock instance. - * - * Input parameters: - * rwlock - pointer to rwlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ - int pthread_rwlock_timedwrlock( pthread_rwlock_t *rwlock, const struct timespec *abstime ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - Watchdog_Interval ticks; - bool do_wait = true; + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + Watchdog_Interval ticks; + bool do_wait; TOD_Absolute_timeout_conversion_results status; - Thread_Control *executing; + Thread_Control *executing; /* * POSIX requires that blocking calls with timeouts that take @@ -66,42 +49,40 @@ int pthread_rwlock_timedwrlock( * then we should not wait. */ status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks ); - if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE ) - do_wait = false; - - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { + do_wait = ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE ); - case OBJECTS_LOCAL: + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - executing = _Thread_Executing; - _CORE_RWLock_Seize_for_writing( - &the_rwlock->RWLock, - executing, - do_wait, - ticks - ); + if ( the_rwlock == NULL ) { + return EINVAL; + } - _Objects_Put( &the_rwlock->Object ); - if ( !do_wait && - (executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) { - if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID ) - return EINVAL; - if ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST || - status == TOD_ABSOLUTE_TIMEOUT_IS_NOW ) - return ETIMEDOUT; - } + executing = _Thread_Executing; + _CORE_RWLock_Seize_for_writing( + &the_rwlock->RWLock, + executing, + do_wait, + ticks, + &lock_context + ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( - (CORE_RWLock_Status) executing->Wait.return_code - ); + if ( + !do_wait + && ( executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) + ) { + if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID ) { + return EINVAL; + } -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( + status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST + || status == TOD_ABSOLUTE_TIMEOUT_IS_NOW + ) { + return ETIMEDOUT; + } } - return EINVAL; + return _POSIX_RWLock_Translate_core_RWLock_return_code( + (CORE_RWLock_Status) executing->Wait.return_code + ); } diff --git a/cpukit/posix/src/prwlocktryrdlock.c b/cpukit/posix/src/prwlocktryrdlock.c index 642ed868ea..a73d122ed6 100644 --- a/cpukit/posix/src/prwlocktryrdlock.c +++ b/cpukit/posix/src/prwlocktryrdlock.c @@ -18,58 +18,31 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/rwlockimpl.h> -#include <rtems/score/thread.h> - -/* - * pthread_rwlock_tryrdlock - * - * This directive attempts to obtain a read only lock on an rwlock instance. - * - * Input parameters: - * rwlock - pointer to rwlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ int pthread_rwlock_tryrdlock( pthread_rwlock_t *rwlock ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - Thread_Control *executing; - - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + Thread_Control *executing; - executing = _Thread_Executing; - _CORE_RWLock_Seize_for_reading( - &the_rwlock->RWLock, - executing, - false, /* do not wait for the rwlock */ - 0 - ); + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - - _Objects_Put( &the_rwlock->Object ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( - (CORE_RWLock_Status) executing->Wait.return_code - ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_rwlock == NULL ) { + return EINVAL; } - return EINVAL; + executing = _Thread_Executing; + _CORE_RWLock_Seize_for_reading( + &the_rwlock->RWLock, + executing, + false, /* do not wait for the rwlock */ + 0, + &lock_context + ); + return _POSIX_RWLock_Translate_core_RWLock_return_code( + (CORE_RWLock_Status) executing->Wait.return_code + ); } diff --git a/cpukit/posix/src/prwlocktrywrlock.c b/cpukit/posix/src/prwlocktrywrlock.c index 065199b88a..a44a54ffb5 100644 --- a/cpukit/posix/src/prwlocktrywrlock.c +++ b/cpukit/posix/src/prwlocktrywrlock.c @@ -18,57 +18,31 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - #include <rtems/posix/rwlockimpl.h> -#include <rtems/score/thread.h> - -/* - * pthread_rwlock_trywrlock - * - * This directive attempts to obtain a Write only lock on an rwlock instance. - * - * Input parameters: - * rwlock - pointer to rwlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ int pthread_rwlock_trywrlock( pthread_rwlock_t *rwlock ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - Thread_Control *executing; - - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + Thread_Control *executing; - executing = _Thread_Executing; - _CORE_RWLock_Seize_for_writing( - &the_rwlock->RWLock, - executing, - false, /* we are not willing to wait */ - 0 - ); + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - _Objects_Put( &the_rwlock->Object ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( - (CORE_RWLock_Status) executing->Wait.return_code - ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_rwlock == NULL ) { + return EINVAL; } - return EINVAL; + executing = _Thread_Executing; + _CORE_RWLock_Seize_for_writing( + &the_rwlock->RWLock, + executing, + false, /* we are not willing to wait */ + 0, + &lock_context + ); + return _POSIX_RWLock_Translate_core_RWLock_return_code( + (CORE_RWLock_Status) executing->Wait.return_code + ); } diff --git a/cpukit/posix/src/prwlockunlock.c b/cpukit/posix/src/prwlockunlock.c index 5dc70995e8..bf6b4deaf0 100644 --- a/cpukit/posix/src/prwlockunlock.c +++ b/cpukit/posix/src/prwlockunlock.c @@ -20,47 +20,22 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - -#include <rtems/system.h> #include <rtems/posix/rwlockimpl.h> -/* - * pthread_rwlock_unlock - * - * This directive attempts to release a lock on an RWLock. - * - * Input parameters: - * rwlock - pointer to rwlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ - int pthread_rwlock_unlock( pthread_rwlock_t *rwlock ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - CORE_RWLock_Status status; + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + CORE_RWLock_Status status; - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - case OBJECTS_LOCAL: - status = _CORE_RWLock_Surrender( &the_rwlock->RWLock, _Thread_Executing ); - _Objects_Put( &the_rwlock->Object ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( status ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_rwlock == NULL ) { + return EINVAL; } - return EINVAL; + status = _CORE_RWLock_Surrender( &the_rwlock->RWLock, &lock_context ); + return _POSIX_RWLock_Translate_core_RWLock_return_code( status ); } diff --git a/cpukit/posix/src/prwlockwrlock.c b/cpukit/posix/src/prwlockwrlock.c index aa35a2c567..635f376e7d 100644 --- a/cpukit/posix/src/prwlockwrlock.c +++ b/cpukit/posix/src/prwlockwrlock.c @@ -28,51 +28,29 @@ THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_RWLock_Control, RWLock.Wait_queue ); -/* - * pthread_rwlock_wrlock - * - * This directive attempts to obtain a write only lock on an rwlock instance. - * - * Input parameters: - * rwlock - pointer to rwlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ - int pthread_rwlock_wrlock( pthread_rwlock_t *rwlock ) { - POSIX_RWLock_Control *the_rwlock; - Objects_Locations location; - Thread_Control *executing; - - the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: + POSIX_RWLock_Control *the_rwlock; + ISR_lock_Context lock_context; + Thread_Control *executing; - executing = _Thread_Executing; - _CORE_RWLock_Seize_for_writing( - &the_rwlock->RWLock, - executing, - true, /* do not timeout -- wait forever */ - 0 - ); + the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context ); - _Objects_Put( &the_rwlock->Object ); - return _POSIX_RWLock_Translate_core_RWLock_return_code( - (CORE_RWLock_Status) executing->Wait.return_code - ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_rwlock == NULL ) { + return EINVAL; } - return EINVAL; + executing = _Thread_Executing; + _CORE_RWLock_Seize_for_writing( + &the_rwlock->RWLock, + executing, + true, /* do not timeout -- wait forever */ + 0, + &lock_context + ); + return _POSIX_RWLock_Translate_core_RWLock_return_code( + (CORE_RWLock_Status) executing->Wait.return_code + ); } |