From c09db57f37e02e8458e3bffce689774546845bef Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 28 Nov 2016 13:28:32 +0100 Subject: score: Fix thread queue context initialization Initialize the thread queue context with invalid data in debug configurations to catch missing set up steps. --- cpukit/score/include/rtems/score/coremuteximpl.h | 1 + cpukit/score/include/rtems/score/threadqimpl.h | 7 ++++--- cpukit/score/src/threadqenqueue.c | 5 +++++ cpukit/score/src/threadrestart.c | 2 +- cpukit/score/src/threadtimeout.c | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h index e3da6a7737..638cf8801c 100644 --- a/cpukit/score/include/rtems/score/coremuteximpl.h +++ b/cpukit/score/include/rtems/score/coremuteximpl.h @@ -253,6 +253,7 @@ 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, diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h index bb35b1718b..760c83c658 100644 --- a/cpukit/score/include/rtems/score/threadqimpl.h +++ b/cpukit/score/include/rtems/score/threadqimpl.h @@ -87,9 +87,10 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Context_initialize( ) { #if defined(RTEMS_DEBUG) - memset( queue_context, 0, sizeof( *queue_context ) ); - queue_context->enqueue_callout = _Thread_queue_Enqueue_do_nothing; - queue_context->deadlock_callout = _Thread_queue_Deadlock_fatal; + memset( queue_context, 0x7f, sizeof( *queue_context ) ); +#if defined(RTEMS_SMP) + _Chain_Initialize_node( &queue_context->Lock_context.Wait.Gate.Node ); +#endif #else (void) queue_context; #endif diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c index 7ffef336b4..4d71ba7492 100644 --- a/cpukit/score/src/threadqenqueue.c +++ b/cpukit/score/src/threadqenqueue.c @@ -420,6 +420,9 @@ void _Thread_queue_Enqueue( Per_CPU_Control *cpu_self; bool success; + _Assert( (uint8_t) (uintptr_t) queue_context->enqueue_callout != 0x7f ); + _Assert( (uint8_t) queue_context->timeout_discipline != 0x7f ); + #if defined(RTEMS_MULTIPROCESSING) if ( _Thread_MP_Is_receive( the_thread ) && the_thread->receive_packet ) { the_thread = _Thread_MP_Allocate_proxy( queue_context->thread_state ); @@ -433,6 +436,7 @@ void _Thread_queue_Enqueue( _Thread_Wait_restore_default( the_thread ); _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context ); _Thread_Wait_tranquilize( the_thread ); + _Assert( (uint8_t) (uintptr_t) queue_context->deadlock_callout != 0x7f ); ( *queue_context->deadlock_callout )( the_thread ); return; } @@ -597,6 +601,7 @@ bool _Thread_queue_Extract_locked( Thread_queue_Context *queue_context ) { + _Thread_queue_Context_clear_priority_updates( queue_context ); #if defined(RTEMS_MULTIPROCESSING) _Thread_queue_MP_set_callout( the_thread, queue_context ); #endif diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index fc934f6529..ac1427b090 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -57,8 +57,8 @@ static void _Thread_Raise_real_priority( { Thread_queue_Context queue_context; - _Thread_queue_Context_clear_priority_updates( &queue_context ); _Thread_Wait_acquire( the_thread, &queue_context ); + _Thread_queue_Context_clear_priority_updates( &queue_context ); if ( priority < the_thread->Real_priority.priority ) { _Thread_Priority_change( diff --git a/cpukit/score/src/threadtimeout.c b/cpukit/score/src/threadtimeout.c index 8297c55c4b..ea270553b2 100644 --- a/cpukit/score/src/threadtimeout.c +++ b/cpukit/score/src/threadtimeout.c @@ -31,8 +31,8 @@ void _Thread_Timeout( Watchdog_Control *watchdog ) the_thread = RTEMS_CONTAINER_OF( watchdog, Thread_Control, Timer.Watchdog ); - _Thread_queue_Context_clear_priority_updates( &queue_context ); _Thread_Wait_acquire( the_thread, &queue_context ); + _Thread_queue_Context_clear_priority_updates( &queue_context ); wait_flags = _Thread_Wait_flags_get( the_thread ); -- cgit v1.2.3