diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-03-18 14:03:01 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-03-18 15:36:58 +0100 |
commit | 5a5fb3b9d6d99d6751d129458217f1a3b5b85ff8 (patch) | |
tree | 9f2296b7e4abaa0da454caea84e2fcbc0eb49fd2 /cpukit/posix/src/pspintrylock.c | |
parent | score: Add _Objects_Get_by_name() (diff) | |
download | rtems-5a5fb3b9d6d99d6751d129458217f1a3b5b85ff8.tar.bz2 |
score: Avoid Giant lock for CORE spinlock
Use an ISR lock to protect the spinlock state. Remove empty attributes.
Update #2555.
Diffstat (limited to 'cpukit/posix/src/pspintrylock.c')
-rw-r--r-- | cpukit/posix/src/pspintrylock.c | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/cpukit/posix/src/pspintrylock.c b/cpukit/posix/src/pspintrylock.c index d304908559..5f132a3193 100644 --- a/cpukit/posix/src/pspintrylock.c +++ b/cpukit/posix/src/pspintrylock.c @@ -18,50 +18,26 @@ #include "config.h" #endif -#include <pthread.h> -#include <errno.h> - -#include <rtems/system.h> #include <rtems/posix/spinlockimpl.h> -/* - * pthread_spin_trylock - * - * This directive allows a thread to poll an attempt at locking a spinlock. - * - * Input parameters: - * spinlock - spinlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ +#include <errno.h> -int pthread_spin_trylock( - pthread_spinlock_t *spinlock -) +int pthread_spin_trylock( pthread_spinlock_t *spinlock ) { - POSIX_Spinlock_Control *the_spinlock = NULL; - Objects_Locations location; - CORE_spinlock_Status status; + POSIX_Spinlock_Control *the_spinlock; + ISR_lock_Context lock_context; + CORE_spinlock_Status status; - if ( !spinlock ) + the_spinlock = _POSIX_Spinlock_Get( spinlock, &lock_context ); + if ( the_spinlock == NULL ) { return EINVAL; - - the_spinlock = _POSIX_Spinlock_Get( spinlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, false, 0 ); - _Objects_Put( &the_spinlock->Object ); - return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; } - return EINVAL; + status = _CORE_spinlock_Seize( + &the_spinlock->Spinlock, + false, + 0, + &lock_context + ); + return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); } |