[rtems commit] score: Initialize thread queue context early

Sebastian Huber sebh at rtems.org
Fri Dec 2 09:36:57 UTC 2016


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Dec  1 20:42:48 2016 +0100

score: Initialize thread queue context early

Initialize thread queue context early preferably outside the critical
section.

Remove implicit _Thread_queue_Context_initialize() from
_Thread_Wait_acquire().

---

 cpukit/libmisc/monitor/mon-task.c                | 1 +
 cpukit/posix/src/mutexsetprioceiling.c           | 2 ++
 cpukit/posix/src/pthread.c                       | 6 ++++--
 cpukit/posix/src/pthreadgetschedparam.c          | 2 +-
 cpukit/posix/src/pthreadsetschedparam.c          | 3 ++-
 cpukit/posix/src/pthreadsetschedprio.c           | 3 ++-
 cpukit/rtems/src/schedulerremoveprocessor.c      | 1 +
 cpukit/rtems/src/semcreate.c                     | 1 +
 cpukit/rtems/src/tasksetpriority.c               | 2 +-
 cpukit/score/include/rtems/score/coremuteximpl.h | 3 +--
 cpukit/score/include/rtems/score/mrspimpl.h      | 2 +-
 cpukit/score/include/rtems/score/threadimpl.h    | 3 ---
 cpukit/score/src/threadrestart.c                 | 6 ++++--
 cpukit/score/src/threadtimeout.c                 | 3 ++-
 testsuites/smptests/smpscheduler03/init.c        | 3 ++-
 testsuites/sptests/spthreadq01/init.c            | 1 +
 16 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/cpukit/libmisc/monitor/mon-task.c b/cpukit/libmisc/monitor/mon-task.c
index 475f5be..fadf51d 100644
--- a/cpukit/libmisc/monitor/mon-task.c
+++ b/cpukit/libmisc/monitor/mon-task.c
@@ -22,6 +22,7 @@ rtems_monitor_task_wait_info(
 {
     Thread_queue_Context queue_context;
 
+    _Thread_queue_Context_initialize( &queue_context );
     _Thread_Wait_acquire( rtems_thread, &queue_context );
 
     canonical_task->state = rtems_thread->current_state;
diff --git a/cpukit/posix/src/mutexsetprioceiling.c b/cpukit/posix/src/mutexsetprioceiling.c
index f483a2b..9288ffd 100644
--- a/cpukit/posix/src/mutexsetprioceiling.c
+++ b/cpukit/posix/src/mutexsetprioceiling.c
@@ -67,6 +67,8 @@ int pthread_mutex_setprioceiling(
       Thread_queue_Context  queue_context;
       Per_CPU_Control      *cpu_self;
 
+      _Thread_queue_Context_initialize( &queue_context );
+      _Thread_queue_Context_clear_priority_updates( &queue_context );
       _CORE_ceiling_mutex_Set_priority(
         &the_mutex->Mutex,
         new_priority,
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index eb7d652..e096dd6 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -91,8 +91,9 @@ void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
   api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic.Timer );
   the_thread = api->thread;
 
-  _Thread_Wait_acquire( the_thread, &queue_context );
+  _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_clear_priority_updates( &queue_context );
+  _Thread_Wait_acquire( the_thread, &queue_context );
 
   if ( _Priority_Node_is_active( &api->Sporadic.Low_priority ) ) {
     _Thread_Priority_add(
@@ -122,8 +123,9 @@ void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread )
 
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
 
-  _Thread_Wait_acquire( the_thread, &queue_context );
+  _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_clear_priority_updates( &queue_context );
+  _Thread_Wait_acquire( the_thread, &queue_context );
 
   /*
    *  This will prevent the thread from consuming its entire "budget"
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
index b60022d..b809db9 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -45,6 +45,7 @@ int pthread_getschedparam(
     return EINVAL;
   }
 
+  _Thread_queue_Context_initialize( &queue_context );
   the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context );
 
   if ( the_thread == NULL ) {
@@ -53,7 +54,6 @@ int pthread_getschedparam(
 
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
 
-  _Thread_queue_Context_initialize( &queue_context );
   _Thread_Wait_acquire_critical( the_thread, &queue_context );
 
   *policy = api->Attributes.schedpolicy;
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 14ea1cd..4da2ebf 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -138,13 +138,14 @@ int pthread_setschedparam(
     return error;
   }
 
+  _Thread_queue_Context_initialize( &queue_context );
+  _Thread_queue_Context_clear_priority_updates( &queue_context );
   the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context );
 
   if ( the_thread == NULL ) {
     return ESRCH;
   }
 
-  _Thread_queue_Context_clear_priority_updates( &queue_context );
   _Thread_Wait_acquire_critical( the_thread, &queue_context );
   error = _POSIX_Set_sched_param(
     the_thread,
diff --git a/cpukit/posix/src/pthreadsetschedprio.c b/cpukit/posix/src/pthreadsetschedprio.c
index 16b6f3f..ff7bd5c 100644
--- a/cpukit/posix/src/pthreadsetschedprio.c
+++ b/cpukit/posix/src/pthreadsetschedprio.c
@@ -27,13 +27,14 @@ int pthread_setschedprio( pthread_t thread, int prio )
   Priority_Control         new_priority;
   bool                     valid;
 
+  _Thread_queue_Context_initialize( &queue_context );
+  _Thread_queue_Context_clear_priority_updates( &queue_context );
   the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context );
 
   if ( the_thread == NULL ) {
     return ESRCH;
   }
 
-  _Thread_queue_Context_clear_priority_updates( &queue_context );
   _Thread_Wait_acquire_critical( the_thread, &queue_context );
 
   scheduler = _Thread_Scheduler_get_home( the_thread );
diff --git a/cpukit/rtems/src/schedulerremoveprocessor.c b/cpukit/rtems/src/schedulerremoveprocessor.c
index 21b7c46..86fd8e5 100644
--- a/cpukit/rtems/src/schedulerremoveprocessor.c
+++ b/cpukit/rtems/src/schedulerremoveprocessor.c
@@ -41,6 +41,7 @@ static bool _Scheduler_Check_processor_removal(
 
   iter_context = arg;
 
+  _Thread_queue_Context_initialize( &queue_context );
   _Thread_Wait_acquire( the_thread, &queue_context );
   _Thread_State_acquire_critical( the_thread, &state_context );
 
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index 10e64f4..77ee3d3 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -168,6 +168,7 @@ rtems_status_code rtems_semaphore_create(
           Thread_queue_Context queue_context;
 
           _Thread_queue_Context_initialize( &queue_context );
+          _Thread_queue_Context_clear_priority_updates( &queue_context );
           _ISR_lock_ISR_disable( &queue_context.Lock_context.Lock_context );
           _CORE_mutex_Acquire_critical(
             &the_semaphore->Core_control.Mutex.Recursive.Mutex,
diff --git a/cpukit/rtems/src/tasksetpriority.c b/cpukit/rtems/src/tasksetpriority.c
index 8f0ce31..c17ff1c 100644
--- a/cpukit/rtems/src/tasksetpriority.c
+++ b/cpukit/rtems/src/tasksetpriority.c
@@ -44,7 +44,6 @@ static rtems_status_code _RTEMS_tasks_Set_priority(
     return RTEMS_INVALID_PRIORITY;
   }
 
-  _Thread_queue_Context_clear_priority_updates( queue_context );
   _Thread_Priority_change(
     the_thread,
     &the_thread->Real_priority,
@@ -78,6 +77,7 @@ rtems_status_code rtems_task_set_priority(
   }
 
   _Thread_queue_Context_initialize( &queue_context );
+  _Thread_queue_Context_clear_priority_updates( &queue_context );
   the_thread = _Thread_Get( id, &queue_context.Lock_context.Lock_context );
 
   if ( the_thread == NULL ) {
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index 638cf88..dead048 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -253,7 +253,6 @@ RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Set_priority(
 
   if ( owner != NULL ) {
     _Thread_Wait_acquire( owner, queue_context );
-    _Thread_queue_Context_clear_priority_updates( queue_context );
     _Thread_Priority_change(
       owner,
       &the_mutex->Priority_ceiling,
@@ -284,7 +283,6 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Set_owner(
   Scheduler_Node   *scheduler_node;
   Per_CPU_Control  *cpu_self;
 
-  _Thread_queue_Context_clear_priority_updates( queue_context );
   _Thread_Wait_acquire_default_critical( owner, &lock_context );
 
   scheduler_node = _Thread_Scheduler_get_home_node( owner );
@@ -341,6 +339,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Seize(
     }
 #endif
 
+    _Thread_queue_Context_clear_priority_updates( queue_context );
     return _CORE_ceiling_mutex_Set_owner(
       the_mutex,
       executing,
diff --git a/cpukit/score/include/rtems/score/mrspimpl.h b/cpukit/score/include/rtems/score/mrspimpl.h
index 1339b50..9773d4a 100644
--- a/cpukit/score/include/rtems/score/mrspimpl.h
+++ b/cpukit/score/include/rtems/score/mrspimpl.h
@@ -132,7 +132,7 @@ RTEMS_INLINE_ROUTINE void _MRSP_Remove_priority(
   Thread_queue_Context *queue_context
 )
 {
-  ISR_lock_Context  lock_context;
+  ISR_lock_Context lock_context;
 
   _Thread_queue_Context_clear_priority_updates( queue_context );
   _Thread_Wait_acquire_default_critical( thread, &lock_context );
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index a38b23c..f131bbd 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -1333,8 +1333,6 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_release_queue_critical(
  * @param[in] the_thread The thread.
  * @param[in] queue_context The thread queue context for the corresponding
  *   _Thread_Wait_release_critical().
- *
- * @see _Thread_queue_Context_initialize().
  */
 RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire_critical(
   Thread_Control       *the_thread,
@@ -1397,7 +1395,6 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_queue_Context_initialize( queue_context );
   _ISR_lock_ISR_disable( &queue_context->Lock_context.Lock_context );
   _Thread_Wait_acquire_critical( the_thread, queue_context );
 }
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index ac1427b..54491d8 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -57,8 +57,9 @@ static void _Thread_Raise_real_priority(
 {
   Thread_queue_Context queue_context;
 
-  _Thread_Wait_acquire( the_thread, &queue_context );
+  _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_clear_priority_updates( &queue_context );
+  _Thread_Wait_acquire( the_thread, &queue_context );
 
   if ( priority < the_thread->Real_priority.priority ) {
     _Thread_Priority_change(
@@ -637,6 +638,8 @@ void _Thread_Restart_self(
       || executing->current_state == STATES_SUSPENDED
   );
 
+  _Thread_queue_Context_initialize( &queue_context );
+  _Thread_queue_Context_clear_priority_updates( &queue_context );
   _Thread_State_acquire_critical( executing, lock_context );
 
   executing->Start.Entry = *entry;
@@ -650,7 +653,6 @@ void _Thread_Restart_self(
   cpu_self = _Thread_Dispatch_disable_critical( lock_context );
   _Thread_State_release( executing, lock_context );
 
-  _Thread_queue_Context_clear_priority_updates( &queue_context );
   _Thread_Wait_acquire_default( executing, lock_context );
   _Thread_Priority_change(
     executing,
diff --git a/cpukit/score/src/threadtimeout.c b/cpukit/score/src/threadtimeout.c
index ea27055..8bcdc38 100644
--- a/cpukit/score/src/threadtimeout.c
+++ b/cpukit/score/src/threadtimeout.c
@@ -31,8 +31,9 @@ void _Thread_Timeout( Watchdog_Control *watchdog )
 
   the_thread = RTEMS_CONTAINER_OF( watchdog, Thread_Control, Timer.Watchdog );
 
-  _Thread_Wait_acquire( the_thread, &queue_context );
+  _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_clear_priority_updates( &queue_context );
+  _Thread_Wait_acquire( the_thread, &queue_context );
 
   wait_flags = _Thread_Wait_flags_get( the_thread );
 
diff --git a/testsuites/smptests/smpscheduler03/init.c b/testsuites/smptests/smpscheduler03/init.c
index 88eb66c..4aa6a01 100644
--- a/testsuites/smptests/smpscheduler03/init.c
+++ b/testsuites/smptests/smpscheduler03/init.c
@@ -52,8 +52,9 @@ static void apply_priority(
   Thread_queue_Context *queue_context
 )
 {
-  _Thread_Wait_acquire(thread, queue_context);
+  _Thread_queue_Context_initialize(queue_context);
   _Thread_queue_Context_clear_priority_updates(queue_context);
+  _Thread_Wait_acquire(thread, queue_context);
   _Thread_Priority_change(
     thread,
     &thread->Real_priority,
diff --git a/testsuites/sptests/spthreadq01/init.c b/testsuites/sptests/spthreadq01/init.c
index afaa652..8f02e4d 100644
--- a/testsuites/sptests/spthreadq01/init.c
+++ b/testsuites/sptests/spthreadq01/init.c
@@ -71,6 +71,7 @@ static rtems_id get_wait_id(test_context *ctx)
   Thread_queue_Context queue_context;
   rtems_id id;
 
+  _Thread_queue_Context_initialize(&queue_context);
   _Thread_Wait_acquire(ctx->master, &queue_context);
   id = _Thread_Wait_get_id(ctx->master);
   _Thread_Wait_release(ctx->master, &queue_context);



More information about the vc mailing list