If an alarm is being set and is the newest deadline
among a set of existing alarms, it would be appended
after the first existing alarm rather than prepended
in front.
This in turn meant the root alarm wasn't getting
rescheduled correctly, especially if the old
deadline was rather distant in the future.
(This was causing the bluetooth disable sequence to
fail intermittently.)
alarm->data = data;
// Add it into the timer list sorted by deadline (earliest deadline first).
- if (list_is_empty(alarms))
+ if (list_is_empty(alarms) || ((alarm_t *)list_front(alarms))->deadline >= alarm->deadline)
list_prepend(alarms, alarm);
else
for (list_node_t *node = list_begin(alarms); node != list_end(alarms); node = list_next(node)) {