An object that tracks scheduled events and automatically cancels them when it is destroyed. More...
#include "event-garbage-collector.h"
Public Member Functions | |
EventGarbageCollector () | |
~EventGarbageCollector () | |
void | Track (EventId event) |
Tracks a new event. More... | |
Private Types | |
typedef std::multiset< EventId > | EventList |
Event list container. More... | |
Private Member Functions | |
void | Cleanup () |
Called when a new event was added and the cleanup limit was exceeded in consequence. More... | |
void | Grow () |
Grow the cleanup limit. More... | |
void | Shrink () |
Shrink the cleanup limit Reduce the cleanup size by factors of two until less than the current event list, then Grow one step. More... | |
Private Attributes | |
const EventList::size_type | CHUNK_INIT_SIZE = 8 |
Initial threshold for cleaning the event list. More... | |
const EventList::size_type | CHUNK_MAX_SIZE = 128 |
Threshold to switch from exponential to linear growth in the cleanup frequency. More... | |
EventList | m_events |
The tracked event list. More... | |
EventList::size_type | m_nextCleanupSize |
Batch size for cleanup. More... | |
An object that tracks scheduled events and automatically cancels them when it is destroyed.
It is useful in situations where multiple instances of the same type of event can simultaneously be scheduled, and when the events should be limited to the lifetime of a container object.
Definition at line 46 of file event-garbage-collector.h.
|
private |
Event list container.
Definition at line 63 of file event-garbage-collector.h.
ns3::EventGarbageCollector::EventGarbageCollector | ( | ) |
Definition at line 32 of file event-garbage-collector.cc.
ns3::EventGarbageCollector::~EventGarbageCollector | ( | ) |
Definition at line 93 of file event-garbage-collector.cc.
References ns3::Simulator::Cancel(), and m_events.
|
private |
Called when a new event was added and the cleanup limit was exceeded in consequence.
Definition at line 67 of file event-garbage-collector.cc.
References Grow(), m_events, m_nextCleanupSize, and Shrink().
Referenced by Track().
|
private |
Grow the cleanup limit.
Increase the cleanup size by the smaller of the current cleanup size (exponential growth), or the CHUNK_MAX_SIZE (linear growth).
Definition at line 48 of file event-garbage-collector.cc.
References CHUNK_MAX_SIZE, and m_nextCleanupSize.
Referenced by Cleanup(), and Shrink().
|
private |
Shrink the cleanup limit Reduce the cleanup size by factors of two until less than the current event list, then Grow one step.
Definition at line 55 of file event-garbage-collector.cc.
References Grow(), m_events, and m_nextCleanupSize.
Referenced by Cleanup().
void ns3::EventGarbageCollector::Track | ( | EventId | event | ) |
Tracks a new event.
[in] | event | the Event to track |
Definition at line 38 of file event-garbage-collector.cc.
References Cleanup(), m_events, and m_nextCleanupSize.
Referenced by ns3::olsr::RoutingProtocol::AssociationTupleTimerExpire(), ns3::tests::EventGarbageCollectorTestCase::DoRun(), ns3::olsr::RoutingProtocol::DupTupleTimerExpire(), ns3::olsr::RoutingProtocol::IfaceAssocTupleTimerExpire(), ns3::olsr::RoutingProtocol::LinkSensing(), ns3::olsr::RoutingProtocol::LinkTupleTimerExpire(), ns3::olsr::RoutingProtocol::MprSelTupleTimerExpire(), ns3::olsr::RoutingProtocol::Nb2hopTupleTimerExpire(), ns3::olsr::RoutingProtocol::PopulateMprSelectorSet(), ns3::olsr::RoutingProtocol::PopulateTwoHopNeighborSet(), ns3::olsr::RoutingProtocol::ProcessTc(), and ns3::olsr::RoutingProtocol::TopologyTupleTimerExpire().
|
private |
Initial threshold for cleaning the event list.
Definition at line 66 of file event-garbage-collector.h.
|
private |
Threshold to switch from exponential to linear growth in the cleanup frequency.
Definition at line 71 of file event-garbage-collector.h.
Referenced by Grow().
|
private |
The tracked event list.
Definition at line 74 of file event-garbage-collector.h.
Referenced by ~EventGarbageCollector(), Cleanup(), Shrink(), and Track().
|
private |