diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-06-13 15:29:04 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-06-13 15:51:21 +0200 |
commit | 80fca28198170a84cde8a9f22dbb29c3a6c4123b (patch) | |
tree | acea5eb27023816bd447d6fe004f8f00a7830d1e /cpukit/score | |
parent | score: Delete unused state WATCHDOG_REMOVE_IT (diff) | |
download | rtems-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.
Diffstat (limited to 'cpukit/score')
-rw-r--r-- | cpukit/score/include/rtems/score/watchdogimpl.h | 23 | ||||
-rw-r--r-- | cpukit/score/src/threadinitialize.c | 2 |
2 files changed, 23 insertions, 2 deletions
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 */ |