[rtems commit] score: Add _Watchdog_Preinitialize()

Sebastian Huber sebh at rtems.org
Sat Jun 13 14:46:34 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sat Jun 13 15:29:04 2015 +0200

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.

---

 cpukit/posix/src/pthread.c                      |  1 +
 cpukit/posix/src/timercreate.c                  |  2 +-
 cpukit/rtems/src/ratemoncreate.c                |  2 +-
 cpukit/rtems/src/timercreate.c                  |  2 +-
 cpukit/rtems/src/timerserver.c                  |  1 +
 cpukit/score/include/rtems/score/watchdogimpl.h | 23 ++++++++++++++++++++++-
 cpukit/score/src/threadinitialize.c             |  2 +-
 testsuites/sptests/spwatchdog/init.c            |  8 ++++----
 8 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 6395ec0..02d86b5 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 6d822b3..a5261cc 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 1f597ec..1ac4a36 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 13a01fe..5c718b9 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 047fd09..29e7bc4 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 ad6ab5b..0e04f64 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 a09693a..3c0a412 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 283f4c8..b96b680 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(




More information about the vc mailing list