score: Add _Watchdog_Preinitialize()

Add an assert to ensure that the watchdog is the proper state for a
_Watchdog_Initialize().  This helps to detect invalid initializations
which may lead to a corrupt watchdog chain.
This commit is contained in:
Sebastian Huber
2015-06-13 15:29:04 +02:00
parent 258d580c42
commit 80fca28198
8 changed files with 32 additions and 9 deletions

View File

@@ -241,6 +241,7 @@ static bool _POSIX_Threads_Create_extension(
_Thread_queue_Initialize( &api->Join_List, THREAD_QUEUE_DISCIPLINE_FIFO );
_Watchdog_Preinitialize( &api->Sporadic_timer );
_Watchdog_Initialize(
&api->Sporadic_timer,
_POSIX_Threads_Sporadic_budget_TSR,

View File

@@ -92,7 +92,7 @@ int timer_create(
ptimer->timer_data.it_interval.tv_sec = 0;
ptimer->timer_data.it_interval.tv_nsec = 0;
_Watchdog_Initialize( &ptimer->Timer, NULL, 0, NULL );
_Watchdog_Preinitialize( &ptimer->Timer );
_Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
*timerid = ptimer->Object.id;

View File

@@ -65,7 +65,7 @@ rtems_status_code rtems_rate_monotonic_create(
the_period->owner = _Thread_Get_executing();
the_period->state = RATE_MONOTONIC_INACTIVE;
_Watchdog_Initialize( &the_period->Timer, NULL, 0, NULL );
_Watchdog_Preinitialize( &the_period->Timer );
_Rate_monotonic_Reset_statistics( the_period );

View File

@@ -75,7 +75,7 @@ rtems_status_code rtems_timer_create(
}
the_timer->the_class = TIMER_DORMANT;
_Watchdog_Initialize( &the_timer->Ticker, NULL, 0, NULL );
_Watchdog_Preinitialize( &the_timer->Ticker );
_Objects_Open(
&_Timer_Information,

View File

@@ -298,6 +298,7 @@ static void _Timer_server_Initialize_watchdogs(
watchdogs->current_snapshot = now;
_Watchdog_Header_initialize( &watchdogs->Header );
_Watchdog_Preinitialize( &watchdogs->System_watchdog );
_Watchdog_Initialize(
&watchdogs->System_watchdog,
_Timer_server_Wakeup,

View File

@@ -20,6 +20,7 @@
#define _RTEMS_SCORE_WATCHDOGIMPL_H
#include <rtems/score/watchdog.h>
#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
#include <rtems/score/isrlock.h>
@@ -269,6 +270,26 @@ void _Watchdog_Tickle (
Watchdog_Header *header
);
/**
* @brief Pre-initializes a watchdog.
*
* This routine must be called before a watchdog is used in any way. The
* exception are statically initialized watchdogs via WATCHDOG_INITIALIZER().
*
* @param[in] the_watchdog The uninitialized watchdog.
*/
RTEMS_INLINE_ROUTINE void _Watchdog_Preinitialize(
Watchdog_Control *the_watchdog
)
{
the_watchdog->state = WATCHDOG_INACTIVE;
#if defined(RTEMS_DEBUG)
the_watchdog->routine = NULL;
the_watchdog->id = 0;
the_watchdog->user_data = NULL;
#endif
}
/**
* This routine initializes the specified watchdog. The watchdog is
* made inactive, the watchdog id and handler routine are set to the
@@ -282,7 +303,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Initialize(
void *user_data
)
{
the_watchdog->state = WATCHDOG_INACTIVE;
_Assert( the_watchdog->state == WATCHDOG_INACTIVE );
the_watchdog->routine = routine;
the_watchdog->id = id;
the_watchdog->user_data = user_data;

View File

@@ -137,7 +137,7 @@ bool _Thread_Initialize(
/*
* Initialize the thread timer
*/
_Watchdog_Initialize( &the_thread->Timer, NULL, 0, NULL );
_Watchdog_Preinitialize( &the_thread->Timer );
#ifdef __RTEMS_STRICT_ORDER_MUTEX__
/* Initialize the head of chain of held mutexes */

View File

@@ -48,7 +48,7 @@ static void init_watchdogs(
rtems_test_assert( _Watchdog_Is_empty( header ) );
rtems_test_assert( _Chain_Is_empty( &header->Iterators ) );
_Watchdog_Initialize( c, NULL, 0, NULL );
_Watchdog_Preinitialize( c );
c->initial = 6;
_Watchdog_Insert( header, c );
rtems_test_assert( c->delta_interval == 6 );
@@ -56,20 +56,20 @@ static void init_watchdogs(
rtems_test_assert( !_Watchdog_Is_empty( header ) );
rtems_test_assert( _Chain_Is_empty( &header->Iterators ) );
_Watchdog_Initialize( a, NULL, 0, NULL );
_Watchdog_Preinitialize( a );
a->initial = 2;
_Watchdog_Insert( header, a );
rtems_test_assert( a->delta_interval == 2 );
rtems_test_assert( c->delta_interval == 4 );
_Watchdog_Initialize( b, NULL, 0, NULL );
_Watchdog_Preinitialize( b );
b->initial = 4;
_Watchdog_Insert( header, b );
rtems_test_assert( a->delta_interval == 2 );
rtems_test_assert( b->delta_interval == 2 );
rtems_test_assert( c->delta_interval == 2 );
_Watchdog_Initialize( d, NULL, 0, NULL );
_Watchdog_Preinitialize( d );
}
static void destroy_watchdogs(