altos: Move comment in ao_sleep_for next to related code
[fw/altos] / src / kernel / ao_task.c
index e430edc6c02f3e5854b5163ebd18afc26d6c0e0e..5b8f9356e922dbe17e839402e862beafab56911b 100644 (file)
@@ -165,13 +165,14 @@ ao_task_check_alarm(uint16_t tick)
 {
        struct ao_task  *alarm, *next;
 
-       ao_list_for_each_entry_safe(alarm, next, &alarm_queue, struct ao_task, alarm_queue) {
-               if ((int16_t) (tick - alarm->alarm) < 0)
-                       break;
-               alarm->alarm = 0;
-               ao_task_from_alarm_queue(alarm);
-               ao_task_to_run_queue(alarm);
-       }
+       ao_arch_critical(
+               ao_list_for_each_entry_safe(alarm, next, &alarm_queue, struct ao_task, alarm_queue) {
+                       if ((int16_t) (tick - alarm->alarm) < 0)
+                               break;
+                       alarm->alarm = 0;
+                       ao_task_from_alarm_queue(alarm);
+                       ao_task_to_run_queue(alarm);
+               });
 }
 
 void
@@ -459,11 +460,11 @@ ao_sleep_for(__xdata void *wchan, uint16_t timeout)
        if (timeout) {
 #if HAS_TASK_QUEUE
                uint32_t flags;
+               flags = ao_arch_irqsave();
+#endif
                /* 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
                 */
-               flags = ao_arch_irqsave();
-#endif
                if (!(ao_cur_task->alarm = ao_time() + timeout + 1))
                        ao_cur_task->alarm = 1;
 #if HAS_TASK_QUEUE