Ensure that ao_alarm waits at least the specified time
authorKeith Packard <keithp@keithp.com>
Sat, 19 Dec 2009 23:31:36 +0000 (15:31 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 19 Dec 2009 23:31:36 +0000 (15:31 -0800)
Because the timer tick may happen soon, it's important to delay by
another tick to ensure that we don't wake up early.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_task.c

index 4664163..4a78766 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;
 }