OSDN Git Service

Fix alarm setting for newer deadlines
authorZach Johnson <zachoverflow@google.com>
Tue, 24 Feb 2015 07:43:03 +0000 (23:43 -0800)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 16 Mar 2015 23:51:34 +0000 (16:51 -0700)
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.)

osi/src/alarm.c

index 553d1f2..57ef1a4 100644 (file)
@@ -130,7 +130,7 @@ void alarm_set(alarm_t *alarm, period_ms_t deadline, alarm_callback_t cb, void *
   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)) {