altos: Update time for next alarm each time a task is added
authorKeith Packard <keithp@keithp.com>
Thu, 29 Aug 2013 03:54:31 +0000 (21:54 -0600)
committerKeith Packard <keithp@keithp.com>
Thu, 29 Aug 2013 03:54:31 +0000 (21:54 -0600)
Adding a task with a sooner timeout than existing alarm tasks was not
correctly updating the time to fire the next alarm, causing tasks to
be delayed by the wrong amount.

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

index 1d9ed41492bba22d094deac324f62fcbd104cc08..e682bd98e466a6031899d6e8744950d5a15bc665 100644 (file)
 #include <ao_task.h>
 
 #ifndef AO_SAMPLE_PROFILE_LOW_PC
-#define AO_SAMPLE_PROFILE_LOW_PC       0x08000000
+#define AO_SAMPLE_PROFILE_LOW_PC       0x08002000
 #endif
 
 #ifndef AO_SAMPLE_PROFILE_HIGH_PC
-#define AO_SAMPLE_PROFILE_HIGH_PC      (AO_SAMPLE_PROFILE_LOW_PC + 44 * 1024)
+#define AO_SAMPLE_PROFILE_HIGH_PC      0x08003000
 #endif
 
 #ifndef AO_SAMPLE_PROFILE_SHIFT
-#define AO_SAMPLE_PROFILE_SHIFT                6
+#define AO_SAMPLE_PROFILE_SHIFT                3
 #endif
 
 #define AO_SAMPLE_PROFILE_RANGE                (AO_SAMPLE_PROFILE_HIGH_PC - AO_SAMPLE_PROFILE_LOW_PC)
index 0aad650898d9c54dddca6d53e6fa2c799aec89d8..4f48e32dcc4c86679d7a6508188e6bf78a35dd3d 100644 (file)
@@ -109,6 +109,8 @@ ao_task_validate_alarm_queue(void)
                                ao_panic(3);
                }
        }
+       if (ao_task_alarm_tick != ao_list_first_entry(&alarm_queue, struct ao_task, alarm_queue)->alarm)
+               ao_panic(4);
 }
 #else
 #define ao_task_validate_alarm_queue()
@@ -123,6 +125,7 @@ ao_task_to_alarm_queue(struct ao_task *task)
        ao_list_for_each_entry(alarm, &alarm_queue, struct ao_task, alarm_queue) {
                if ((int16_t) (alarm->alarm - task->alarm) >= 0) {
                        ao_list_insert(&task->alarm_queue, alarm->alarm_queue.prev);
+                       ao_task_alarm_tick = ao_list_first_entry(&alarm_queue, struct ao_task, alarm_queue)->alarm;
                        ao_task_validate_alarm_queue();
                        return;
                }