[rtems commit] score: Replace _API_Mutex_Is_locked()

Sebastian Huber sebh at rtems.org
Wed May 27 10:24:37 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed May 27 11:43:44 2015 +0200

score: Replace _API_Mutex_Is_locked()

Replace _API_Mutex_Is_locked() with _API_Mutex_Is_owner().

---

 cpukit/score/Makefile.am                           |  2 +-
 cpukit/score/include/rtems/score/apimutex.h        | 11 ++++--
 .../src/{apimutexislocked.c => apimutexisowner.c}  |  8 ++--
 testsuites/support/include/tmacros.h               | 45 +++++++++-------------
 4 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 11399e9..3b2c5bc 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -160,7 +160,7 @@ endif
 
 ## CORE_APIMUTEX_C_FILES
 libscore_a_SOURCES += src/apimutex.c \
-    src/apimutexlock.c src/apimutexislocked.c src/apimutexunlock.c
+    src/apimutexlock.c src/apimutexisowner.c src/apimutexunlock.c
 
 ## CORE_BARRIER_C_FILES
 libscore_a_SOURCES += src/corebarrier.c src/corebarrierrelease.c \
diff --git a/cpukit/score/include/rtems/score/apimutex.h b/cpukit/score/include/rtems/score/apimutex.h
index 628ba5d..615f60b 100644
--- a/cpukit/score/include/rtems/score/apimutex.h
+++ b/cpukit/score/include/rtems/score/apimutex.h
@@ -85,7 +85,12 @@ void _API_Mutex_Lock( API_Mutex_Control *mutex );
  */
 void _API_Mutex_Unlock( API_Mutex_Control *mutex );
 
-bool _API_Mutex_Is_locked( const API_Mutex_Control *mutex );
+/**
+ * @brief Checks if the specified API mutex is owned by the executing thread.
+ *
+ * @param[in] mutex The API mutex.
+ */
+bool _API_Mutex_Is_owner( const API_Mutex_Control *mutex );
 
 /** @} */
 
@@ -120,9 +125,9 @@ static inline void _RTEMS_Unlock_allocator( void )
   _API_Mutex_Unlock( _RTEMS_Allocator_Mutex );
 }
 
-static inline bool _RTEMS_Check_if_allocator_is_locked( void )
+static inline bool _RTEMS_Allocator_is_owner( void )
 {
-  return _API_Mutex_Is_locked( _RTEMS_Allocator_Mutex );
+  return _API_Mutex_Is_owner( _RTEMS_Allocator_Mutex );
 }
 
 SCORE_EXTERN API_Mutex_Control *_Once_Mutex;
diff --git a/cpukit/score/src/apimutexislocked.c b/cpukit/score/src/apimutexisowner.c
similarity index 64%
rename from cpukit/score/src/apimutexislocked.c
rename to cpukit/score/src/apimutexisowner.c
index 6435fbf..a80c664 100644
--- a/cpukit/score/src/apimutexislocked.c
+++ b/cpukit/score/src/apimutexisowner.c
@@ -1,8 +1,6 @@
 /**
  * @file
  *
- * @brief Check if the specified API mutex is locked.
- *
  * @ingroup ScoreAPIMutex
  */
 
@@ -20,9 +18,9 @@
 #endif
 
 #include <rtems/score/apimutex.h>
-#include <rtems/score/coremuteximpl.h>
+#include <rtems/score/threadimpl.h>
 
-bool _API_Mutex_Is_locked( const API_Mutex_Control *the_mutex )
+bool _API_Mutex_Is_owner( const API_Mutex_Control *the_mutex )
 {
-  return _CORE_mutex_Is_locked( &the_mutex->Mutex );
+  return the_mutex->Mutex.holder == _Thread_Get_executing();
 }
diff --git a/testsuites/support/include/tmacros.h b/testsuites/support/include/tmacros.h
index a67bb95..e35ef33 100644
--- a/testsuites/support/include/tmacros.h
+++ b/testsuites/support/include/tmacros.h
@@ -70,30 +70,23 @@ extern "C" {
 #endif
 
 /*
- *  Check that that the allocator mutex is not locked. It should never
- *  be locked unless inside a service which is allocating a resource.
- *
- *  This test is only valid when in a non-SMP system.  In an SMP system
- *  another cpu may be allocating a resource while we are computing.
+ *  Check that that the allocator mutex is not owned by the executing thread.
  */
-#if defined SMPTEST
-  #define check_if_allocator_mutex_is_unlocked() 
-#else
-  #include <rtems/score/apimutex.h>
-  #define check_if_allocator_mutex_is_unlocked() \
-    do { \
-      if ( _RTEMS_Check_if_allocator_is_locked() ) { \
-        printk( \
-          "\nRTEMS Allocator Mutex is locked and should not be.\n" \
-          "Detected at %s:%d\n", \
-          __FILE__, \
-          __LINE__ \
-        ); \
-        FLUSH_OUTPUT(); \
-        rtems_test_exit( 1 ); \
-      } \
-    } while ( 0 )
-#endif
+#include <rtems/score/apimutex.h>
+#define check_if_allocator_mutex_is_not_owned() \
+  do { \
+    if ( _RTEMS_Allocator_is_owner() ) { \
+      printk( \
+        "\nRTEMS Allocator Mutex is owned by executing thread " \
+          "and should not be.\n" \
+        "Detected at %s:%d\n", \
+        __FILE__, \
+        __LINE__ \
+      ); \
+      FLUSH_OUTPUT(); \
+      rtems_test_exit( 1 ); \
+    } \
+  } while ( 0 )
 
 /*
  *  These macros properly report errors within the Classic API
@@ -121,7 +114,7 @@ extern "C" {
 #define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \
   do { \
     check_dispatch_disable_level( _level ); \
-    check_if_allocator_mutex_is_unlocked(); \
+    check_if_allocator_mutex_is_not_owned(); \
     fatal_directive_check_status_only( _stat, _desired, _msg ); \
   } while ( 0 )
 
@@ -139,7 +132,7 @@ extern "C" {
   if ( (_stat != -1) && (errno) != (_desired) ) { \
     long statx = _stat; \
     check_dispatch_disable_level( 0 ); \
-    check_if_allocator_mutex_is_unlocked(); \
+    check_if_allocator_mutex_is_not_owned(); \
     printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \
 	    (_msg), _desired, strerror(_desired), \
             statx, errno, strerror(errno) ); \
@@ -153,7 +146,7 @@ extern "C" {
 #define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
   do { \
     check_dispatch_disable_level( _level ); \
-    check_if_allocator_mutex_is_unlocked(); \
+    check_if_allocator_mutex_is_not_owned(); \
     if ( (_stat) != (_desired) ) { \
       printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
               (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \



More information about the vc mailing list