Ensure that ao_alarm waits at least the specified time
[fw/altos] / src / ao_task.c
index 4664163d6a1a7ccdd6801575f2b182d58e8d3f6a..4a78766e2828664b1687b09f0ea28a02ac987066 100644 (file)
@@ -217,7 +217,10 @@ ao_wakeup(__xdata void *wchan)
 void
 ao_alarm(uint16_t delay)
 {
-       if (!(ao_cur_task->alarm = ao_time() + delay))
+       /* Make sure we sleep *at least* delay ticks, which means adding
+        * one to account for the fact that we may be close to the next tick
+        */
+       if (!(ao_cur_task->alarm = ao_time() + delay + 1))
                ao_cur_task->alarm = 1;
 }