[rtems commit] posix: Fix pthread_spin_unlock() error status

Sebastian Huber sebh at rtems.org
Wed May 25 10:45:37 UTC 2016


Module:    rtems
Branch:    master
Commit:    9ec7d492b951efec32520bff7106e21e16e9c74d
Changeset: http://git.rtems.org/rtems/commit/?id=9ec7d492b951efec32520bff7106e21e16e9c74d

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed May 25 08:37:28 2016 +0200

posix: Fix pthread_spin_unlock() error status

Close #2719.

---

 cpukit/posix/src/pspinlocktranslatereturncode.c     |  3 +--
 cpukit/score/include/rtems/score/corespinlockimpl.h |  8 ++------
 cpukit/score/src/corespinlockrelease.c              | 13 ++++---------
 testsuites/psxtests/psxspin01/psxspin01.scn         |  7 ++++---
 testsuites/psxtests/psxspin01/test.c                |  9 +++++++--
 5 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/cpukit/posix/src/pspinlocktranslatereturncode.c b/cpukit/posix/src/pspinlocktranslatereturncode.c
index af8c8ac..6d3e9b0 100644
--- a/cpukit/posix/src/pspinlocktranslatereturncode.c
+++ b/cpukit/posix/src/pspinlocktranslatereturncode.c
@@ -31,8 +31,7 @@ static int _POSIX_Spinlock_Return_codes[CORE_SPINLOCK_STATUS_LAST + 1] = {
   EPERM,                    /* CORE_SPINLOCK_NOT_HOLDER */
   -1,                       /* CORE_SPINLOCK_TIMEOUT */
   EBUSY,                    /* CORE_SPINLOCK_IS_BUSY */
-  EBUSY,                    /* CORE_SPINLOCK_UNAVAILABLE */
-  0                         /* CORE_SPINLOCK_NOT_LOCKED */
+  EBUSY                     /* CORE_SPINLOCK_UNAVAILABLE */
 };
 
 
diff --git a/cpukit/score/include/rtems/score/corespinlockimpl.h b/cpukit/score/include/rtems/score/corespinlockimpl.h
index 189bddb..fd4fcf2 100644
--- a/cpukit/score/include/rtems/score/corespinlockimpl.h
+++ b/cpukit/score/include/rtems/score/corespinlockimpl.h
@@ -58,15 +58,11 @@ typedef enum {
   /** This status indicates that the spinlock is currently locked and thus
    *  unavailable.
    */
-  CORE_SPINLOCK_UNAVAILABLE,
-  /** This status indicates that the spinlock is not currently locked and thus
-   *  should not be released.
-   */
-  CORE_SPINLOCK_NOT_LOCKED
+  CORE_SPINLOCK_UNAVAILABLE
 }   CORE_spinlock_Status;
 
 /** This is a shorthand for the last status code. */
-#define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_NOT_LOCKED
+#define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_UNAVAILABLE
 
 /** This indicates the lock is available. */
 #define CORE_SPINLOCK_UNLOCKED 0
diff --git a/cpukit/score/src/corespinlockrelease.c b/cpukit/score/src/corespinlockrelease.c
index 358d352..6f2ea71 100644
--- a/cpukit/score/src/corespinlockrelease.c
+++ b/cpukit/score/src/corespinlockrelease.c
@@ -29,17 +29,12 @@ CORE_spinlock_Status _CORE_spinlock_Surrender(
   _CORE_spinlock_Acquire_critical( the_spinlock, lock_context );
 
     /*
-     *  It must locked before it can be unlocked.
-     */
-    if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) {
-      _CORE_spinlock_Release( the_spinlock, lock_context );
-      return CORE_SPINLOCK_NOT_LOCKED;
-    }
-
-    /*
      *  It must locked by the current thread before it can be unlocked.
      */
-    if ( the_spinlock->holder != _Thread_Executing ) {
+    if (
+      the_spinlock->lock != CORE_SPINLOCK_LOCKED
+        || the_spinlock->holder != _Thread_Executing
+    ) {
       _CORE_spinlock_Release( the_spinlock, lock_context );
       return CORE_SPINLOCK_NOT_HOLDER;
     }
diff --git a/testsuites/psxtests/psxspin01/psxspin01.scn b/testsuites/psxtests/psxspin01/psxspin01.scn
index 87ea2db..5c0e752 100644
--- a/testsuites/psxtests/psxspin01/psxspin01.scn
+++ b/testsuites/psxtests/psxspin01/psxspin01.scn
@@ -1,4 +1,4 @@
-*** POSIX SPINLOCK TEST 01 ***
+*** BEGIN OF TEST PSXSPIN 1 ***
 pthread_spin_init( NULL, PTHREAD_PROCESS_PRIVATE ) -- EINVAL
 pthread_spin_init( NULL, PTHREAD_PROCESS_SHARED ) -- EINVAL
 pthread_spin_init( &spinlock, 0x1234 ) -- EINVAL
@@ -14,7 +14,7 @@ pthread_spin_lock( &spinlock ) -- EINVAL
 pthread_spin_trylock( &spinlock ) -- EINVAL
 pthread_spin_unlock( &spinlock ) -- EINVAL
 pthread_spin_destroy( &spinlock ) -- EINVAL
-pthread_spin_unlock( &Spinlock ) -- already unlocked OK
+pthread_spin_unlock( &Spinlock ) -- EPERM
 pthread_spin_lock( &Spinlock ) -- OK
 pthread_spin_lock( &Spinlock ) -- EDEADLK
 pthread_spin_trylock( &Spinlock ) -- EDEADLK
@@ -23,9 +23,10 @@ pthread_spin_trylock( &Spinlock ) -- OK
 pthread_spin_unlock( &Spinlock ) -- OK
 pthread_spin_lock( &Spinlock ) from Thread -- OK
 sleep to allow main thread to run
+pthread_spin_unlock( &Spinlock ) -- EPERM
 pthread_spin_lock( &Spinlock ) -- OK
 pthread_spin_unlock( &Spinlock ) from Thread -- OK
 pthread_spin_destroy( &Spinlock ) -- EBUSY
 pthread_spin_unlock( &Spinlock ) -- OK
 pthread_spin_destroy( &Spinlock ) -- OK
-*** END OF POSIX SPINLOCK TEST 01 ***
+*** END OF TEST PSXSPIN 1 ***
diff --git a/testsuites/psxtests/psxspin01/test.c b/testsuites/psxtests/psxspin01/test.c
index f6fda64..270cdcf 100644
--- a/testsuites/psxtests/psxspin01/test.c
+++ b/testsuites/psxtests/psxspin01/test.c
@@ -146,9 +146,9 @@ int main(
   status = pthread_spin_destroy( &spinlock );
   rtems_test_assert( status == EINVAL );
 
-  puts( "pthread_spin_unlock( &Spinlock ) -- already unlocked OK" );
+  puts( "pthread_spin_unlock( &Spinlock ) -- EPERM" );
   status = pthread_spin_unlock( &Spinlock );
-  rtems_test_assert( status == 0 );
+  rtems_test_assert( status == EPERM );
 
   /* Now some basic locking and unlocking with a deadlock verification */
   puts( "pthread_spin_lock( &Spinlock ) -- OK" );
@@ -200,6 +200,11 @@ int main(
    */
 
   mainThreadSpinning = 1;
+
+  puts( "pthread_spin_unlock( &Spinlock ) -- EPERM" );
+  status = pthread_spin_unlock( &Spinlock );
+  rtems_test_assert( status == EPERM );
+
   puts( "pthread_spin_lock( &Spinlock ) -- OK" );
   status = pthread_spin_lock( &Spinlock );
   rtems_test_assert( status == 0 );




More information about the vc mailing list