A Discrete-Event Network Simulator
API
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ns3::EventGarbageCollector Class Reference

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< EventIdEventList
 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...
 

Detailed Description

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.

Member Typedef Documentation

◆ EventList

typedef std::multiset<EventId> ns3::EventGarbageCollector::EventList
private

Event list container.

Definition at line 63 of file event-garbage-collector.h.

Constructor & Destructor Documentation

◆ EventGarbageCollector()

ns3::EventGarbageCollector::EventGarbageCollector ( )

Definition at line 32 of file event-garbage-collector.cc.

◆ ~EventGarbageCollector()

ns3::EventGarbageCollector::~EventGarbageCollector ( )

Definition at line 84 of file event-garbage-collector.cc.

References ns3::Simulator::Cancel(), and m_events.

Member Function Documentation

◆ Cleanup()

void ns3::EventGarbageCollector::Cleanup ( )
private

Called when a new event was added and the cleanup limit was exceeded in consequence.

Definition at line 64 of file event-garbage-collector.cc.

References Grow(), m_events, m_nextCleanupSize, and Shrink().

Referenced by Track().

◆ Grow()

void ns3::EventGarbageCollector::Grow ( )
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 47 of file event-garbage-collector.cc.

References CHUNK_MAX_SIZE, and m_nextCleanupSize.

Referenced by Cleanup(), and Shrink().

◆ Shrink()

void ns3::EventGarbageCollector::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 54 of file event-garbage-collector.cc.

References Grow(), m_events, and m_nextCleanupSize.

Referenced by Cleanup().

◆ Track()

void ns3::EventGarbageCollector::Track ( EventId  event)

Member Data Documentation

◆ CHUNK_INIT_SIZE

const EventList::size_type ns3::EventGarbageCollector::CHUNK_INIT_SIZE = 8
private

Initial threshold for cleaning the event list.

Definition at line 66 of file event-garbage-collector.h.

◆ CHUNK_MAX_SIZE

const EventList::size_type ns3::EventGarbageCollector::CHUNK_MAX_SIZE = 128
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().

◆ m_events

EventList ns3::EventGarbageCollector::m_events
private

The tracked event list.

Definition at line 74 of file event-garbage-collector.h.

Referenced by Cleanup(), Shrink(), Track(), and ~EventGarbageCollector().

◆ m_nextCleanupSize

EventList::size_type ns3::EventGarbageCollector::m_nextCleanupSize
private

Batch size for cleanup.

Definition at line 73 of file event-garbage-collector.h.

Referenced by Cleanup(), Grow(), Shrink(), and Track().


The documentation for this class was generated from the following files: