[rtems commit] score: Split _Watchdog_Adjust()

Sebastian Huber sebh at rtems.org
Tue Apr 14 06:22:29 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Apr 10 15:51:50 2015 +0200

score: Split _Watchdog_Adjust()

Split _Watchdog_Adjust() into _Watchdog_Adjust_backward() and
_Watchdog_Adjust_forward().  Remove Watchdog_Adjust_directions,
_Watchdog_Adjust_seconds() and _Watchdog_Adjust_ticks().  This avoids to
check the same condition again.

Update #2307.

---

 cpukit/rtems/src/timerserver.c                  |  2 +-
 cpukit/score/include/rtems/score/watchdogimpl.h | 78 +++++++------------------
 cpukit/score/src/coretodset.c                   |  6 +-
 cpukit/score/src/watchdogadjust.c               | 67 ++++++++++-----------
 4 files changed, 56 insertions(+), 97 deletions(-)

diff --git a/cpukit/rtems/src/timerserver.c b/cpukit/rtems/src/timerserver.c
index e4fe56f..00f29cc 100644
--- a/cpukit/rtems/src/timerserver.c
+++ b/cpukit/rtems/src/timerserver.c
@@ -275,7 +275,7 @@ static void _Timer_server_Process_tod_watchdogs(
       *  TOD has been set backwards.
       */
      delta = last_snapshot - snapshot;
-     _Watchdog_Adjust( &watchdogs->Chain, WATCHDOG_BACKWARD, delta );
+     _Watchdog_Adjust_backward( &watchdogs->Chain, delta );
   }
 
   watchdogs->last_snapshot = snapshot;
diff --git a/cpukit/score/include/rtems/score/watchdogimpl.h b/cpukit/score/include/rtems/score/watchdogimpl.h
index d50e279..9eb0951 100644
--- a/cpukit/score/include/rtems/score/watchdogimpl.h
+++ b/cpukit/score/include/rtems/score/watchdogimpl.h
@@ -53,22 +53,6 @@ extern "C" {
   }
 
 /**
- *  @brief the manner in which a watchdog chain may
- *  be adjusted by the @ref _Watchdog_Adjust routine.
- *
- *  The following enumerated type details the manner in which
- *  a watchdog chain may be adjusted by the @ref _Watchdog_Adjust
- *  routine.  The direction indicates a movement FORWARD
- *  or BACKWARD in time.
- */
-typedef enum {
-  /** adjust delta value forward */
-  WATCHDOG_FORWARD,
-  /** adjust delta value backward */
-  WATCHDOG_BACKWARD
-} Watchdog_Adjust_directions;
-
-/**
  *  @brief Watchdog synchronization level.
  *
  *  This used for synchronization purposes
@@ -121,20 +105,29 @@ Watchdog_States _Watchdog_Remove (
 );
 
 /**
- *  @brief Adjusts the @a header watchdog chain in the forward
- *  or backward @a direction for @a units ticks.
+ *  @brief Adjusts the header watchdog chain in the backward direction for
+ *  units ticks.
  *
- *  This routine adjusts the @a header watchdog chain in the forward
- *  or backward @a direction for @a units ticks.
+ *  @param[in] header The watchdog chain.
+ *  @param[in] units The units of ticks to adjust.
+ */
+void _Watchdog_Adjust_backward(
+  Chain_Control     *header,
+  Watchdog_Interval  units
+);
+
+/**
+ *  @brief Adjusts the header watchdog chain in the forward direction for units
+ *  ticks.
  *
- *  @param[in] header is the watchdog chain to adjust
- *  @param[in] direction is the direction to adjust @a header
- *  @param[in] units is the number of units to adjust @a header
+ *  This may lead to several _Watchdog_Tickle() invocations.
+ *
+ *  @param[in] header The watchdog chain.
+ *  @param[in] units The units of ticks to adjust.
  */
-void _Watchdog_Adjust (
-  Chain_Control              *header,
-  Watchdog_Adjust_directions  direction,
-  Watchdog_Interval           units
+void _Watchdog_Adjust_forward(
+  Chain_Control     *header,
+  Watchdog_Interval  units
 );
 
 /**
@@ -312,37 +305,6 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Insert_seconds(
 }
 
 /**
- * This routine adjusts the seconds watchdog chain in the forward
- * or backward DIRECTION for UNITS seconds.  This is invoked when the
- * current time of day is changed.
- */
-
-RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_seconds(
-  Watchdog_Adjust_directions direction,
-  Watchdog_Interval          units
-)
-{
-
-  _Watchdog_Adjust( &_Watchdog_Seconds_chain, direction, units );
-
-}
-
-/**
- * This routine adjusts the ticks watchdog chain in the forward
- * or backward DIRECTION for UNITS ticks.
- */
-
-RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_ticks(
-  Watchdog_Adjust_directions direction,
-  Watchdog_Interval          units
-)
-{
-
-  _Watchdog_Adjust( &_Watchdog_Ticks_chain, direction, units );
-
-}
-
-/**
  * This routine resets THE_WATCHDOG timer to its state at INSERT
  * time.  This routine is valid only on interval watchdog timers
  * and is used to make an interval watchdog timer fire "every" so
diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c
index 6006e66..8c4ef8b 100644
--- a/cpukit/score/src/coretodset.c
+++ b/cpukit/score/src/coretodset.c
@@ -31,15 +31,17 @@ void _TOD_Set_with_timestamp(
   Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod_as_timestamp );
   Watchdog_Interval seconds_now;
   ISR_lock_Context lock_context;
+  Chain_Control *header;
 
   _Thread_Disable_dispatch();
 
   seconds_now = _TOD_Seconds_since_epoch();
+  header = &_Watchdog_Seconds_chain;
 
   if ( seconds_next < seconds_now )
-    _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds_now - seconds_next );
+    _Watchdog_Adjust_backward( header, seconds_now - seconds_next );
   else
-    _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, seconds_next - seconds_now );
+    _Watchdog_Adjust_forward( header, seconds_next - seconds_now );
 
   _TOD_Acquire( tod, &lock_context );
   tod->now = *tod_as_timestamp;
diff --git a/cpukit/score/src/watchdogadjust.c b/cpukit/score/src/watchdogadjust.c
index bbfda4d..5d84104 100644
--- a/cpukit/score/src/watchdogadjust.c
+++ b/cpukit/score/src/watchdogadjust.c
@@ -18,57 +18,52 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/score/isr.h>
 #include <rtems/score/watchdogimpl.h>
+#include <rtems/score/chainimpl.h>
+#include <rtems/score/isrlevel.h>
 
-void _Watchdog_Adjust(
-  Chain_Control               *header,
-  Watchdog_Adjust_directions   direction,
-  Watchdog_Interval            units
+void _Watchdog_Adjust_backward(
+  Chain_Control     *header,
+  Watchdog_Interval  units
 )
 {
   ISR_Level level;
 
   _ISR_Disable( level );
 
-  /*
-   * NOTE: It is safe NOT to make 'header' a pointer
-   *       to volatile data (contrast this with watchdoginsert.c)
-   *       because we call _Watchdog_Tickle() below and
-   *       hence the compiler must not assume *header to remain
-   *       unmodified across that call.
-   *
-   *       Till Straumann, 7/2003
-   */
   if ( !_Chain_Is_empty( header ) ) {
-    switch ( direction ) {
-      case WATCHDOG_BACKWARD:
-        _Watchdog_First( header )->delta_interval += units;
-        break;
-      case WATCHDOG_FORWARD:
-        while ( units ) {
-          if ( units < _Watchdog_First( header )->delta_interval ) {
-            _Watchdog_First( header )->delta_interval -= units;
-            break;
-          } else {
-            units -= _Watchdog_First( header )->delta_interval;
-            _Watchdog_First( header )->delta_interval = 1;
+     _Watchdog_First( header )->delta_interval += units;
+  }
+
+  _ISR_Enable( level );
+}
+
+void _Watchdog_Adjust_forward(
+  Chain_Control     *header,
+  Watchdog_Interval  units
+)
+{
+  ISR_Level level;
+
+  _ISR_Disable( level );
+
+  while ( !_Chain_Is_empty( header ) && units > 0 ) {
+    Watchdog_Control *first = _Watchdog_First( header );
 
-            _ISR_Enable( level );
+    if ( units < first->delta_interval ) {
+      first->delta_interval -= units;
+      break;
+    } else {
+      units -= first->delta_interval;
+      first->delta_interval = 1;
 
-            _Watchdog_Tickle( header );
+      _ISR_Enable( level );
 
-            _ISR_Disable( level );
+      _Watchdog_Tickle( header );
 
-            if ( _Chain_Is_empty( header ) )
-              break;
-          }
-        }
-        break;
+      _ISR_Disable( level );
     }
   }
 
   _ISR_Enable( level );
-
 }




More information about the vc mailing list