Add/Remove event timers by event name
Using the event name as the key, each timer an event adds to the list of
timers are associated to that event. This allows quick removal of those
timers when the event is removed and more efficient searching for a
timer within the smaller list of timers per event name.
Change-Id: I4624918d3a3bbe2a5224cde4bc3fc529e5b40df3
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.cpp b/control/actions.cpp
index 3c3b194..029a69a 100644
--- a/control/actions.cpp
+++ b/control/actions.cpp
@@ -29,20 +29,30 @@
{
return !std::get<hasOwnerPos>(s);
});
- if (setTimer &&
- zone.findTimer(group, actions) ==
- std::end(zone.getTimerEvents()))
+ auto it = zone.getTimerEvents().find(__func__);
+ if (it != zone.getTimerEvents().end())
{
- zone.addTimer(group, actions, tConf);
- }
- else
- {
- // Stop and remove any timers for this group
- auto timer = zone.findTimer(group, actions);
- if (timer != std::end(zone.getTimerEvents()))
+ auto& timers = it->second;
+ auto timerIter = zone.findTimer(group, actions, timers);
+ if (setTimer && timerIter == timers.end())
{
- zone.removeTimer(timer);
+ // No timer exists yet for action, add timer
+ zone.addTimer(__func__, group, actions, tConf);
}
+ else if (!setTimer && timerIter != timers.end())
+ {
+ // Remove any timer for this group
+ timers.erase(timerIter);
+ if (timers.empty())
+ {
+ zone.getTimerEvents().erase(it);
+ }
+ }
+ }
+ else if (setTimer)
+ {
+ // No timer exists yet for event, add timer
+ zone.addTimer(__func__, group, actions, tConf);
}
}
catch (const std::out_of_range& oore)