[PATCH] score: Unify CORE mutex seize/surrender

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Sep 27 13:25:25 UTC 2016


Use the Thread_Control::resource_count for the no protocol mutexes.
Merge the no protocol and priority inherit CORE mutex seize/surrender
operations.
---
 cpukit/libnetworking/rtems/rtems_glue.c          |  2 +
 cpukit/posix/src/mutexlocksupp.c                 |  3 +-
 cpukit/posix/src/mutexunlock.c                   |  3 +-
 cpukit/rtems/src/semobtain.c                     |  3 +-
 cpukit/rtems/src/semrelease.c                    |  4 +-
 cpukit/score/include/rtems/score/coremuteximpl.h | 93 ++----------------------
 cpukit/score/src/apimutexlock.c                  |  1 +
 cpukit/score/src/apimutexunlock.c                |  1 +
 8 files changed, 18 insertions(+), 92 deletions(-)

diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
index 9a7f82f..46f8765 100644
--- a/cpukit/libnetworking/rtems/rtems_glue.c
+++ b/cpukit/libnetworking/rtems/rtems_glue.c
@@ -379,6 +379,7 @@ rtems_bsdnet_semaphore_obtain (void)
 	_Thread_queue_Context_set_no_timeout( &queue_context );
 	status = _CORE_recursive_mutex_Seize (
 		&the_networkSemaphore->Core_control.Mutex.Recursive,
+		CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
 		_Thread_Executing,
 		true,			/* wait */
 		_CORE_recursive_mutex_Seize_nested,
@@ -412,6 +413,7 @@ rtems_bsdnet_semaphore_release (void)
 	_ISR_lock_ISR_disable(&queue_context.Lock_context.Lock_context);
 	status = _CORE_recursive_mutex_Surrender(
 		&the_networkSemaphore->Core_control.Mutex.Recursive,
+		CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
 		_Thread_Executing,
 		&queue_context
 	);
diff --git a/cpukit/posix/src/mutexlocksupp.c b/cpukit/posix/src/mutexlocksupp.c
index 1da6238..ea4c4e3 100644
--- a/cpukit/posix/src/mutexlocksupp.c
+++ b/cpukit/posix/src/mutexlocksupp.c
@@ -76,7 +76,7 @@ int _POSIX_Mutex_Lock_support(
       );
       break;
     case POSIX_MUTEX_NO_PROTOCOL:
-      status = _CORE_recursive_mutex_Seize_no_protocol(
+      status = _CORE_recursive_mutex_Seize(
         &the_mutex->Mutex.Recursive,
         POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS,
         executing,
@@ -89,6 +89,7 @@ int _POSIX_Mutex_Lock_support(
       _Assert( the_mutex->protocol == POSIX_MUTEX_PRIORITY_INHERIT );
       status = _CORE_recursive_mutex_Seize(
         &the_mutex->Mutex.Recursive,
+        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
         executing,
         wait,
         _POSIX_Mutex_Lock_nested,
diff --git a/cpukit/posix/src/mutexunlock.c b/cpukit/posix/src/mutexunlock.c
index 3144314..c15f7e6 100644
--- a/cpukit/posix/src/mutexunlock.c
+++ b/cpukit/posix/src/mutexunlock.c
@@ -53,7 +53,7 @@ int pthread_mutex_unlock(
       );
       break;
     case POSIX_MUTEX_NO_PROTOCOL:
-      status = _CORE_recursive_mutex_Surrender_no_protocol(
+      status = _CORE_recursive_mutex_Surrender(
         &the_mutex->Mutex.Recursive,
         POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS,
         executing,
@@ -64,6 +64,7 @@ int pthread_mutex_unlock(
       _Assert( the_mutex->protocol == POSIX_MUTEX_PRIORITY_INHERIT );
       status = _CORE_recursive_mutex_Surrender(
         &the_mutex->Mutex.Recursive,
+        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
         executing,
         &queue_context
       );
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index 9afef54..b81612e 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -75,6 +75,7 @@ rtems_status_code rtems_semaphore_obtain(
     case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
       status = _CORE_recursive_mutex_Seize(
         &the_semaphore->Core_control.Mutex.Recursive,
+        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
         executing,
         wait,
         _CORE_recursive_mutex_Seize_nested,
@@ -91,7 +92,7 @@ rtems_status_code rtems_semaphore_obtain(
       );
       break;
     case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
-      status = _CORE_recursive_mutex_Seize_no_protocol(
+      status = _CORE_recursive_mutex_Seize(
         &the_semaphore->Core_control.Mutex.Recursive,
         _Semaphore_Get_operations( the_semaphore ),
         executing,
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
index 39c467d..40860a1 100644
--- a/cpukit/rtems/src/semrelease.c
+++ b/cpukit/rtems/src/semrelease.c
@@ -52,6 +52,7 @@ rtems_status_code rtems_semaphore_release( rtems_id id )
     case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
       status = _CORE_recursive_mutex_Surrender(
         &the_semaphore->Core_control.Mutex.Recursive,
+        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
         executing,
         &queue_context
       );
@@ -64,13 +65,12 @@ rtems_status_code rtems_semaphore_release( rtems_id id )
       );
       break;
     case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
-      _CORE_recursive_mutex_Surrender_no_protocol(
+      status = _CORE_recursive_mutex_Surrender(
         &the_semaphore->Core_control.Mutex.Recursive,
         _Semaphore_Get_operations( the_semaphore ),
         executing,
         &queue_context
       );
-      status = STATUS_SUCCESSFUL;
       break;
     case SEMAPHORE_VARIANT_SIMPLE_BINARY:
       status = _CORE_semaphore_Surrender(
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index d30e38d..2580606 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -134,6 +134,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_nested(
 
 RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize(
   CORE_recursive_mutex_Control  *the_mutex,
+  const Thread_queue_Operations *operations,
   Thread_Control                *executing,
   bool                           wait,
   Status_Control              ( *nested )( CORE_recursive_mutex_Control * ),
@@ -163,7 +164,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize(
 
   return _CORE_mutex_Seize_slow(
     &the_mutex->Mutex,
-    CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
+    operations,
     executing,
     wait,
     queue_context
@@ -171,9 +172,10 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize(
 }
 
 RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender(
-  CORE_recursive_mutex_Control *the_mutex,
-  Thread_Control               *executing,
-  Thread_queue_Context         *queue_context
+  CORE_recursive_mutex_Control  *the_mutex,
+  const Thread_queue_Operations *operations,
+  Thread_Control                *executing,
+  Thread_queue_Context          *queue_context
 )
 {
   unsigned int        nest_level;
@@ -209,91 +211,8 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender(
     heads,
     executing,
     queue_context,
-    CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS
-  );
-  return STATUS_SUCCESSFUL;
-}
-
-RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_no_protocol(
-  CORE_recursive_mutex_Control  *the_mutex,
-  const Thread_queue_Operations *operations,
-  Thread_Control                *executing,
-  bool                           wait,
-  Status_Control              ( *nested )( CORE_recursive_mutex_Control * ),
-  Thread_queue_Context          *queue_context
-)
-{
-  Thread_Control *owner;
-
-  _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context );
-
-  owner = _CORE_mutex_Get_owner( &the_mutex->Mutex );
-
-  if ( owner == NULL ) {
-    _CORE_mutex_Set_owner( &the_mutex->Mutex, executing );
-    _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
-    return STATUS_SUCCESSFUL;
-  }
-
-  if ( owner == executing ) {
-    Status_Control status;
-
-    status = ( *nested )( the_mutex );
-    _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
-    return status;
-  }
-
-  return _CORE_mutex_Seize_slow(
-    &the_mutex->Mutex,
-    operations,
-    executing,
-    wait,
-    queue_context
-  );
-}
-
-RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender_no_protocol(
-  CORE_recursive_mutex_Control  *the_mutex,
-  const Thread_queue_Operations *operations,
-  Thread_Control                *executing,
-  Thread_queue_Context          *queue_context
-)
-{
-  unsigned int    nest_level;
-  Thread_Control *new_owner;
-
-  _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context );
-
-  if ( !_CORE_mutex_Is_owner( &the_mutex->Mutex, executing ) ) {
-    _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
-    return STATUS_NOT_OWNER;
-  }
-
-  nest_level = the_mutex->nest_level;
-
-  if ( nest_level > 0 ) {
-    the_mutex->nest_level = nest_level - 1;
-    _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
-    return STATUS_SUCCESSFUL;
-  }
-
-  new_owner = _Thread_queue_First_locked(
-    &the_mutex->Mutex.Wait_queue,
     operations
   );
-  _CORE_mutex_Set_owner( &the_mutex->Mutex, new_owner );
-
-  if ( new_owner == NULL ) {
-    _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
-    return STATUS_SUCCESSFUL;
-  }
-
-  _Thread_queue_Extract_critical(
-    &the_mutex->Mutex.Wait_queue.Queue,
-    operations,
-    new_owner,
-    queue_context
-  );
   return STATUS_SUCCESSFUL;
 }
 
diff --git a/cpukit/score/src/apimutexlock.c b/cpukit/score/src/apimutexlock.c
index cf90a76..879562d 100644
--- a/cpukit/score/src/apimutexlock.c
+++ b/cpukit/score/src/apimutexlock.c
@@ -36,6 +36,7 @@ void _API_Mutex_Lock( API_Mutex_Control *the_mutex )
   _Thread_queue_Context_set_no_timeout( &queue_context );
   _CORE_recursive_mutex_Seize(
     &the_mutex->Mutex,
+    CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
     _Thread_Executing,
     true,
     _CORE_recursive_mutex_Seize_nested,
diff --git a/cpukit/score/src/apimutexunlock.c b/cpukit/score/src/apimutexunlock.c
index f04e47a..e1fe645 100644
--- a/cpukit/score/src/apimutexunlock.c
+++ b/cpukit/score/src/apimutexunlock.c
@@ -35,6 +35,7 @@ void _API_Mutex_Unlock( API_Mutex_Control *the_mutex )
   _ISR_lock_ISR_disable( &queue_context.Lock_context.Lock_context );
   _CORE_recursive_mutex_Surrender(
     &the_mutex->Mutex,
+    CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
     _Thread_Executing,
     &queue_context
   );
-- 
1.8.4.5



More information about the devel mailing list