Execute all the due wakeup events in SipWakeupTimer.
Events are sorted by periods. So events of larger periods may have trigger
time (i.e., when the event should be processed) earlier than the ones of smaller
periods. So need to scan the whole queue looking for due events. The scan takes
O(n) time but we expect the queue size to be small.
Change-Id: I08bd3bd9d4bb8decb78f3c91c943396463ca023a
diff --git a/java/com/android/server/sip/SipWakeupTimer.java b/java/com/android/server/sip/SipWakeupTimer.java
index 9cc26b0..76780c0 100644
--- a/java/com/android/server/sip/SipWakeupTimer.java
+++ b/java/com/android/server/sip/SipWakeupTimer.java
@@ -173,7 +173,7 @@
long triggerTime = event.mTriggerTime;
if (DEBUG_TIMER) {
- Log.d(TAG, " add event " + event + " scheduled at "
+ Log.d(TAG, " add event " + event + " scheduled on "
+ showTime(triggerTime) + " at " + showTime(now)
+ ", #events=" + mEventQueue.size());
printQueue();
@@ -267,10 +267,10 @@
if (stopped() || mEventQueue.isEmpty()) return;
for (MyEvent event : mEventQueue) {
- if (event.mTriggerTime != triggerTime) break;
+ if (event.mTriggerTime != triggerTime) continue;
if (DEBUG_TIMER) Log.d(TAG, "execute " + event);
- event.mLastTriggerTime = event.mTriggerTime;
+ event.mLastTriggerTime = triggerTime;
event.mTriggerTime += event.mPeriod;
// run the callback in the handler thread to prevent deadlock
@@ -324,6 +324,8 @@
}
}
+ // Sort the events by mMaxPeriod so that the first event can be used to
+ // align events with larger periods
private static class MyEventComparator implements Comparator<MyEvent> {
public int compare(MyEvent e1, MyEvent e2) {
if (e1 == e2) return 0;