summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-06-13 15:29:04 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-06-13 15:51:21 +0200
commit80fca28198170a84cde8a9f22dbb29c3a6c4123b (patch)
treeacea5eb27023816bd447d6fe004f8f00a7830d1e
parentscore: Delete unused state WATCHDOG_REMOVE_IT (diff)
downloadrtems-80fca28198170a84cde8a9f22dbb29c3a6c4123b.tar.bz2
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.
-rw-r--r--cpukit/posix/src/pthread.c1
-rw-r--r--cpukit/posix/src/timercreate.c2
-rw-r--r--cpukit/rtems/src/ratemoncreate.c2
-rw-r--r--cpukit/rtems/src/timercreate.c2
-rw-r--r--cpukit/rtems/src/timerserver.c1
-rw-r--r--cpukit/score/include/rtems/score/watchdogimpl.h23
-rw-r--r--cpukit/score/src/threadinitialize.c2
-rw-r--r--testsuites/sptests/spwatchdog/init.c8
8 files changed, 32 insertions, 9 deletions
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 6395ec0ebd..02d86b5536 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -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,
diff --git a/cpukit/posix/src/timercreate.c b/cpukit/posix/src/timercreate.c
index 6d822b3928..a5261cc57a 100644
--- a/cpukit/posix/src/timercreate.c
+++ b/cpukit/posix/src/timercreate.c
@@ -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;
diff --git a/cpukit/rtems/src/ratemoncreate.c b/cpukit/rtems/src/ratemoncreate.c
index 1f597ec944..1ac4a36b6e 100644
--- a/cpukit/rtems/src/ratemoncreate.c
+++ b/cpukit/rtems/src/ratemoncreate.c
@@ -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 );
diff --git a/cpukit/rtems/src/timercreate.c b/cpukit/rtems/src/timercreate.c
index 13a01feda9..5c718b94c9 100644
--- a/cpukit/rtems/src/timercreate.c
+++ b/cpukit/rtems/src/timercreate.c
@@ -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,
diff --git a/cpukit/rtems/src/timerserver.c b/cpukit/rtems/src/timerserver.c
index 047fd0978e..29e7bc4f36 100644
--- a/cpukit/rtems/src/timerserver.c
+++ b/cpukit/rtems/src/timerserver.c
@@ -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,
diff --git a/cpukit/score/include/rtems/score/watchdogimpl.h b/cpukit/score/include/rtems/score/watchdogimpl.h
index ad6ab5bcb9..0e04f64d7b 100644
--- a/cpukit/score/include/rtems/score/watchdogimpl.h
+++ b/cpukit/score/include/rtems/score/watchdogimpl.h
@@ -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>
@@ -270,6 +271,26 @@ void _Watchdog_Tickle (
);
/**
+ * @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
* specified values.
@@ -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;
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index a09693acc0..3c0a412aee 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -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 */
diff --git a/testsuites/sptests/spwatchdog/init.c b/testsuites/sptests/spwatchdog/init.c
index 283f4c87a0..b96b680e74 100644
--- a/testsuites/sptests/spwatchdog/init.c
+++ b/testsuites/sptests/spwatchdog/init.c
@@ -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(