[PATCH 1/8] score: Simplify thread queue acquire/release

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Sep 6 12:40:21 UTC 2016


---
 cpukit/posix/include/rtems/posix/condimpl.h        |  7 ++--
 cpukit/posix/include/rtems/posix/psignalimpl.h     | 10 ++----
 cpukit/rtems/src/semdelete.c                       |  4 +--
 cpukit/rtems/src/semflush.c                        |  4 +--
 cpukit/rtems/src/semsetpriority.c                  |  4 +--
 cpukit/score/include/rtems/score/corebarrierimpl.h | 10 ++----
 cpukit/score/include/rtems/score/coremsgimpl.h     | 15 ++------
 cpukit/score/include/rtems/score/coremuteximpl.h   | 10 ++----
 cpukit/score/include/rtems/score/corerwlockimpl.h  | 10 ++----
 cpukit/score/include/rtems/score/coresemimpl.h     | 10 ++----
 cpukit/score/include/rtems/score/mrspimpl.h        |  7 ++--
 cpukit/score/include/rtems/score/threadimpl.h      | 10 +++---
 cpukit/score/include/rtems/score/threadqimpl.h     | 42 ++++++++++++++++------
 cpukit/score/src/threadqenqueue.c                  |  4 +--
 cpukit/score/src/threadqfirst.c                    |  8 ++---
 cpukit/score/src/threadrestart.c                   |  5 +--
 16 files changed, 68 insertions(+), 92 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/condimpl.h b/cpukit/posix/include/rtems/posix/condimpl.h
index 70a0707..fc4cfd3 100644
--- a/cpukit/posix/include/rtems/posix/condimpl.h
+++ b/cpukit/posix/include/rtems/posix/condimpl.h
@@ -68,10 +68,7 @@ RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Acquire_critical(
   Thread_queue_Context              *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &the_cond->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &the_cond->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Release(
@@ -79,7 +76,7 @@ RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Release(
   Thread_queue_Context              *queue_context
 )
 {
-  _Thread_queue_Release( &the_cond->Wait_queue, &queue_context->Lock_context );
+  _Thread_queue_Release( &the_cond->Wait_queue, queue_context );
 }
 
 /**
diff --git a/cpukit/posix/include/rtems/posix/psignalimpl.h b/cpukit/posix/include/rtems/posix/psignalimpl.h
index 62c1a85..cccc3da 100644
--- a/cpukit/posix/include/rtems/posix/psignalimpl.h
+++ b/cpukit/posix/include/rtems/posix/psignalimpl.h
@@ -77,20 +77,14 @@ RTEMS_INLINE_ROUTINE void _POSIX_signals_Acquire(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Acquire(
-    &_POSIX_signals_Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire( &_POSIX_signals_Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _POSIX_signals_Release(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Release(
-    &_POSIX_signals_Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Release( &_POSIX_signals_Wait_queue, queue_context );
 }
 
 /**
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
index fa0c25a..a9fb863 100644
--- a/cpukit/rtems/src/semdelete.c
+++ b/cpukit/rtems/src/semdelete.c
@@ -46,7 +46,7 @@ rtems_status_code rtems_semaphore_delete(
 
   _Thread_queue_Acquire_critical(
     &the_semaphore->Core_control.Wait_queue,
-    &queue_context.Lock_context
+    &queue_context
   );
 
   switch ( the_semaphore->variant ) {
@@ -81,7 +81,7 @@ rtems_status_code rtems_semaphore_delete(
   if ( status != STATUS_SUCCESSFUL ) {
     _Thread_queue_Release(
       &the_semaphore->Core_control.Wait_queue,
-      &queue_context.Lock_context
+      &queue_context
     );
     _Objects_Allocator_unlock();
     return _Status_Get( status );
diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
index 3970d22..b7e8786 100644
--- a/cpukit/rtems/src/semflush.c
+++ b/cpukit/rtems/src/semflush.c
@@ -39,7 +39,7 @@ rtems_status_code rtems_semaphore_flush( rtems_id id )
 
   _Thread_queue_Acquire_critical(
     &the_semaphore->Core_control.Wait_queue,
-    &queue_context.Lock_context
+    &queue_context
   );
   _Thread_queue_Context_set_MP_callout(
     &queue_context,
@@ -51,7 +51,7 @@ rtems_status_code rtems_semaphore_flush( rtems_id id )
     case SEMAPHORE_VARIANT_MRSP:
       _Thread_queue_Release(
         &the_semaphore->Core_control.Wait_queue,
-        &queue_context.Lock_context
+        &queue_context
       );
       return RTEMS_NOT_DEFINED;
 #endif
diff --git a/cpukit/rtems/src/semsetpriority.c b/cpukit/rtems/src/semsetpriority.c
index 5c331bb..f992d99 100644
--- a/cpukit/rtems/src/semsetpriority.c
+++ b/cpukit/rtems/src/semsetpriority.c
@@ -54,7 +54,7 @@ static rtems_status_code _Semaphore_Set_priority(
 
   _Thread_queue_Acquire_critical(
     &the_semaphore->Core_control.Wait_queue,
-    &queue_context->Lock_context
+    queue_context
   );
 
   switch ( the_semaphore->variant ) {
@@ -108,7 +108,7 @@ static rtems_status_code _Semaphore_Set_priority(
 
   _Thread_queue_Release(
     &the_semaphore->Core_control.Wait_queue,
-    &queue_context->Lock_context
+    queue_context
   );
 
   *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
diff --git a/cpukit/score/include/rtems/score/corebarrierimpl.h b/cpukit/score/include/rtems/score/corebarrierimpl.h
index a7256b9..d5d6365 100644
--- a/cpukit/score/include/rtems/score/corebarrierimpl.h
+++ b/cpukit/score/include/rtems/score/corebarrierimpl.h
@@ -59,10 +59,7 @@ RTEMS_INLINE_ROUTINE void _CORE_barrier_Acquire_critical(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &the_barrier->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &the_barrier->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_barrier_Release(
@@ -70,10 +67,7 @@ RTEMS_INLINE_ROUTINE void _CORE_barrier_Release(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Release(
-    &the_barrier->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Release( &the_barrier->Wait_queue, queue_context );
 }
 
 /**
diff --git a/cpukit/score/include/rtems/score/coremsgimpl.h b/cpukit/score/include/rtems/score/coremsgimpl.h
index 3b811c9..e33e330 100644
--- a/cpukit/score/include/rtems/score/coremsgimpl.h
+++ b/cpukit/score/include/rtems/score/coremsgimpl.h
@@ -313,10 +313,7 @@ RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire(
   Thread_queue_Context       *queue_context
 )
 {
-  _Thread_queue_Acquire(
-    &the_message_queue->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire( &the_message_queue->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire_critical(
@@ -324,10 +321,7 @@ RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire_critical(
   Thread_queue_Context       *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &the_message_queue->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &the_message_queue->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Release(
@@ -335,10 +329,7 @@ RTEMS_INLINE_ROUTINE void _CORE_message_queue_Release(
   Thread_queue_Context       *queue_context
 )
 {
-  _Thread_queue_Release(
-    &the_message_queue->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Release( &the_message_queue->Wait_queue, queue_context );
 }
 
 /**
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index ce53b23..680c6d5 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -56,10 +56,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Acquire_critical(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &the_mutex->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &the_mutex->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_mutex_Release(
@@ -67,10 +64,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Release(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Release(
-    &the_mutex->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Release( &the_mutex->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE Thread_Control *_CORE_mutex_Get_owner(
diff --git a/cpukit/score/include/rtems/score/corerwlockimpl.h b/cpukit/score/include/rtems/score/corerwlockimpl.h
index ff881fa..330d9ac 100644
--- a/cpukit/score/include/rtems/score/corerwlockimpl.h
+++ b/cpukit/score/include/rtems/score/corerwlockimpl.h
@@ -71,10 +71,7 @@ RTEMS_INLINE_ROUTINE void _CORE_RWLock_Acquire_critical(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &the_rwlock->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &the_rwlock->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_RWLock_Release(
@@ -82,10 +79,7 @@ RTEMS_INLINE_ROUTINE void _CORE_RWLock_Release(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Release(
-    &the_rwlock->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Release( &the_rwlock->Wait_queue, queue_context );
 }
 
 /**
diff --git a/cpukit/score/include/rtems/score/coresemimpl.h b/cpukit/score/include/rtems/score/coresemimpl.h
index 5a28726..44e1672 100644
--- a/cpukit/score/include/rtems/score/coresemimpl.h
+++ b/cpukit/score/include/rtems/score/coresemimpl.h
@@ -58,10 +58,7 @@ RTEMS_INLINE_ROUTINE void _CORE_semaphore_Acquire_critical(
   Thread_queue_Context   *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &the_semaphore->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Release(
@@ -69,10 +66,7 @@ RTEMS_INLINE_ROUTINE void _CORE_semaphore_Release(
   Thread_queue_Context   *queue_context
 )
 {
-  _Thread_queue_Release(
-    &the_semaphore->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Release( &the_semaphore->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(
diff --git a/cpukit/score/include/rtems/score/mrspimpl.h b/cpukit/score/include/rtems/score/mrspimpl.h
index c136a20..a2a25ae 100644
--- a/cpukit/score/include/rtems/score/mrspimpl.h
+++ b/cpukit/score/include/rtems/score/mrspimpl.h
@@ -66,10 +66,7 @@ RTEMS_INLINE_ROUTINE void _MRSP_Acquire_critical(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Acquire_critical(
-    &mrsp->Wait_queue,
-    &queue_context->Lock_context
-  );
+  _Thread_queue_Acquire_critical( &mrsp->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE void _MRSP_Release(
@@ -77,7 +74,7 @@ RTEMS_INLINE_ROUTINE void _MRSP_Release(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Release( &mrsp->Wait_queue, &queue_context->Lock_context );
+  _Thread_queue_Release( &mrsp->Wait_queue, queue_context );
 }
 
 RTEMS_INLINE_ROUTINE bool _MRSP_Restore_priority_filter(
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 965b2d1..cfa952e 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -368,7 +368,7 @@ RTEMS_INLINE_ROUTINE void _Thread_State_acquire_critical(
   ISR_lock_Context *lock_context
 )
 {
-  _Thread_queue_Acquire_critical( &the_thread->Join_queue, lock_context );
+  _Thread_queue_Do_acquire_critical( &the_thread->Join_queue, lock_context );
 }
 
 RTEMS_INLINE_ROUTINE void _Thread_State_acquire(
@@ -376,7 +376,8 @@ RTEMS_INLINE_ROUTINE void _Thread_State_acquire(
   ISR_lock_Context *lock_context
 )
 {
-  _Thread_queue_Acquire( &the_thread->Join_queue, lock_context );
+  _ISR_lock_ISR_disable( lock_context );
+  _Thread_State_acquire_critical( the_thread, lock_context );
 }
 
 RTEMS_INLINE_ROUTINE Thread_Control *_Thread_State_acquire_for_executing(
@@ -397,7 +398,7 @@ RTEMS_INLINE_ROUTINE void _Thread_State_release_critical(
   ISR_lock_Context *lock_context
 )
 {
-  _Thread_queue_Release_critical( &the_thread->Join_queue, lock_context );
+  _Thread_queue_Do_release_critical( &the_thread->Join_queue, lock_context );
 }
 
 RTEMS_INLINE_ROUTINE void _Thread_State_release(
@@ -405,7 +406,8 @@ RTEMS_INLINE_ROUTINE void _Thread_State_release(
   ISR_lock_Context *lock_context
 )
 {
-  _Thread_queue_Release( &the_thread->Join_queue, lock_context );
+  _Thread_State_release_critical( the_thread, lock_context );
+  _ISR_lock_ISR_enable( lock_context );
 }
 
 #if defined(RTEMS_DEBUG)
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index 8a3b991..641c618 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -350,7 +350,7 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_release(
   _ISR_lock_ISR_enable( lock_context );
 }
 
-RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire_critical(
+RTEMS_INLINE_ROUTINE void _Thread_queue_Do_acquire_critical(
   Thread_queue_Control *the_thread_queue,
   ISR_lock_Context     *lock_context
 )
@@ -365,13 +365,24 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire_critical(
 #endif
 }
 
+RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire_critical(
+  Thread_queue_Control *the_thread_queue,
+  Thread_queue_Context *queue_context
+)
+{
+  _Thread_queue_Do_acquire_critical(
+    the_thread_queue,
+    &queue_context->Lock_context
+  );
+}
+
 RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire(
   Thread_queue_Control *the_thread_queue,
-  ISR_lock_Context     *lock_context
+  Thread_queue_Context *queue_context
 )
 {
-  _ISR_lock_ISR_disable( lock_context );
-  _Thread_queue_Acquire_critical( the_thread_queue, lock_context );
+  _ISR_lock_ISR_disable( &queue_context->Lock_context );
+  _Thread_queue_Acquire_critical( the_thread_queue, queue_context );
 }
 
 #if defined(RTEMS_DEBUG)
@@ -387,7 +398,7 @@ RTEMS_INLINE_ROUTINE bool _Thread_queue_Is_lock_owner(
 }
 #endif
 
-RTEMS_INLINE_ROUTINE void _Thread_queue_Release_critical(
+RTEMS_INLINE_ROUTINE void _Thread_queue_Do_release_critical(
   Thread_queue_Control *the_thread_queue,
   ISR_lock_Context     *lock_context
 )
@@ -404,13 +415,24 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Release_critical(
   );
 }
 
+RTEMS_INLINE_ROUTINE void _Thread_queue_Release_critical(
+  Thread_queue_Control *the_thread_queue,
+  Thread_queue_Context *queue_context
+)
+{
+  _Thread_queue_Do_release_critical(
+    the_thread_queue,
+    &queue_context->Lock_context
+  );
+}
+
 RTEMS_INLINE_ROUTINE void _Thread_queue_Release(
   Thread_queue_Control *the_thread_queue,
-  ISR_lock_Context     *lock_context
+  Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Release_critical( the_thread_queue, lock_context );
-  _ISR_lock_ISR_enable( lock_context );
+  _Thread_queue_Release_critical( the_thread_queue, queue_context );
+  _ISR_lock_ISR_enable( &queue_context->Lock_context );
 }
 
 Thread_Control *_Thread_queue_Do_dequeue(
@@ -541,7 +563,7 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Enqueue(
   Thread_queue_Context queue_context;
 
   _Thread_queue_Context_initialize( &queue_context );
-  _Thread_queue_Acquire( the_thread_queue, &queue_context.Lock_context );
+  _Thread_queue_Acquire( the_thread_queue, &queue_context );
   _Thread_queue_Context_set_expected_level( &queue_context, expected_level );
   if ( discipline == WATCHDOG_ABSOLUTE ) {
     _Thread_queue_Context_set_absolute_timeout( &queue_context, timeout );
@@ -662,7 +684,7 @@ void _Thread_queue_Unblock_critical(
  *   Thread_Control       *first;
  *
  *   _Thread_queue_Context_initialize( &queue_context, NULL );
- *   _Thread_queue_Acquire( &mutex->Queue, &queue_context.Lock_context );
+ *   _Thread_queue_Acquire( &mutex->Queue, queue_context );
  *
  *   first = _Thread_queue_First_locked( &mutex->Queue );
  *   mutex->owner = first;
diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c
index 5a7fd6d..81b3948 100644
--- a/cpukit/score/src/threadqenqueue.c
+++ b/cpukit/score/src/threadqenqueue.c
@@ -641,7 +641,7 @@ Thread_Control *_Thread_queue_Do_dequeue(
 
   _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_set_MP_callout( &queue_context, mp_callout );
-  _Thread_queue_Acquire( the_thread_queue, &queue_context.Lock_context );
+  _Thread_queue_Acquire( the_thread_queue, &queue_context );
 
   the_thread = _Thread_queue_First_locked( the_thread_queue, operations );
 
@@ -653,7 +653,7 @@ Thread_Control *_Thread_queue_Do_dequeue(
       &queue_context
     );
   } else {
-    _Thread_queue_Release( the_thread_queue, &queue_context.Lock_context );
+    _Thread_queue_Release( the_thread_queue, &queue_context );
   }
 
   return the_thread;
diff --git a/cpukit/score/src/threadqfirst.c b/cpukit/score/src/threadqfirst.c
index 790ea8c..0828c1f 100644
--- a/cpukit/score/src/threadqfirst.c
+++ b/cpukit/score/src/threadqfirst.c
@@ -25,12 +25,12 @@ Thread_Control *_Thread_queue_First(
   const Thread_queue_Operations *operations
 )
 {
-  Thread_Control   *the_thread;
-  ISR_lock_Context  lock_context;
+  Thread_Control       *the_thread;
+  Thread_queue_Context  queue_context;
 
-  _Thread_queue_Acquire( the_thread_queue, &lock_context );
+  _Thread_queue_Acquire( the_thread_queue, &queue_context );
   the_thread = _Thread_queue_First_locked( the_thread_queue, operations );
-  _Thread_queue_Release( the_thread_queue, &lock_context );
+  _Thread_queue_Release( the_thread_queue, &queue_context );
 
   return the_thread;
 }
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 8e93d45..b7804a5 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -119,10 +119,7 @@ static void _Thread_Wake_up_joining_threads( Thread_Control *the_thread )
 #endif
 
   _Thread_queue_Context_initialize( &join_context.Base );
-  _Thread_queue_Acquire(
-    &the_thread->Join_queue,
-    &join_context.Base.Lock_context
-  );
+  _Thread_queue_Acquire( &the_thread->Join_queue, &join_context.Base );
   _Thread_queue_Flush_critical(
     &the_thread->Join_queue.Queue,
     THREAD_JOIN_TQ_OPERATIONS,
-- 
1.8.4.5




More information about the devel mailing list