util: fix "delete event in the same event" bug in scheduler.
Change-Id: I3e46b7d8af182f9cb207b0bb0946ee58473d0a70
diff --git a/src/util/scheduler.cpp b/src/util/scheduler.cpp
index c4fc1d8..13a6c3a 100644
--- a/src/util/scheduler.cpp
+++ b/src/util/scheduler.cpp
@@ -109,7 +109,7 @@
void
Scheduler::cancelEvent(const EventId& eventId)
{
- if (!eventId->isValid())
+ if (!static_cast<bool>(eventId) || !eventId->isValid())
return; // event already fired or cancelled
if (static_cast<EventQueue::iterator>(*eventId) != m_scheduledEvent) {
@@ -152,16 +152,22 @@
head->m_event();
if (head->m_period < 0)
{
- head->m_eventId->invalidate();
- m_events.erase(head);
+ if(head->m_eventId->isValid())
+ {
+ head->m_eventId->invalidate();
+ m_events.erase(head);
+ }
}
else
{
+ bool validity = head->m_eventId->isValid();
+
// "reschedule" and update EventId data of the event
EventInfo event(now + head->m_period, *head);
EventQueue::iterator i = m_events.insert(event);
i->m_eventId->reset(i);
- m_events.erase(head);
+ if(validity)
+ m_events.erase(head);
}
}