]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
simplify timer virtualisation logic a bit
authoridgay <idgay>
Tue, 8 Aug 2006 22:46:29 +0000 (22:46 +0000)
committeridgay <idgay>
Tue, 8 Aug 2006 22:46:29 +0000 (22:46 +0000)
tos/lib/timer/VirtualizeTimerC.nc

index 666803d4a17fed2297353dc3c8fb208b6607a45e..d5793a46072d898e5a389e4f80a0b9993a3db3a6 100644 (file)
@@ -78,7 +78,6 @@ implementation
 
        int32_t elapsed = then - timer->t0;
        int32_t remaining = timer->dt - elapsed;
-       bool compute_min_remaining = TRUE;
 
        // If the elapsed time is negative, then t0 is in the future, so
        // don't process it.  This implies:
@@ -90,7 +89,6 @@ implementation
          if (timer->isoneshot)
          {
            timer->isrunning = FALSE;
-           compute_min_remaining = FALSE;
          }
          else
          {
@@ -103,13 +101,14 @@ implementation
          signal Timer.fired[num]();
        }
 
-       // check isrunning in case the timer was stopped in the fired event
-
-       if (compute_min_remaining && timer->isrunning)
+       // check isrunning in case the timer was stopped in the fired
+       // event or this was a one shot timer; note that a one shot
+       // timer that was restarted in its fired event will push us
+       // through here with remaining < 0, but we've already scheduled
+       // an executeTimers in that case
+       if (timer->isrunning)
        {
-          if (remaining < 0)
-            min_remaining = 0;
-         else if (remaining < min_remaining)
+         if (remaining < min_remaining)
            min_remaining = remaining;
          min_remaining_isset = TRUE;
        }
@@ -120,11 +119,13 @@ implementation
     {
       uint32_t now = call TimerFrom.getNow();
       uint32_t elapsed = now - then;
-      if (min_remaining <= elapsed)
+      if (min_remaining < 0 || (uint32_t)min_remaining <= elapsed)
        post executeTimersNow();
       else
        call TimerFrom.startOneShotAt(now, min_remaining - elapsed);
     }
+    if (dosleep)
+      t3 = TCNT3 - tt0;
   }