A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
event-garbage-collector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INESC Porto
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
7 */
8#ifndef EVENT_GARBAGE_COLLECTOR_H
9#define EVENT_GARBAGE_COLLECTOR_H
10
11#include "ns3/event-id.h"
12#include "ns3/simulator.h"
13
14#include <set>
15
16/**
17 * \file
18 * \ingroup events
19 * \ingroup core-helpers
20 * ns3::EventGarbageCollector declaration.
21 */
22
23namespace ns3
24{
25
26/**
27 * \ingroup events
28 * \ingroup core-helpers
29 *
30 * \brief An object that tracks scheduled events and automatically
31 * cancels them when it is destroyed. It is useful in situations
32 * where multiple instances of the same type of event can
33 * simultaneously be scheduled, and when the events should be limited
34 * to the lifetime of a container object.
35 */
37{
38 public:
40
41 /**
42 * \brief Tracks a new event
43 * \param [in] event the Event to track
44 */
45 void Track(EventId event);
46
48
49 private:
50 /** Event list container */
51 typedef std::multiset<EventId> EventList;
52
53 /** Initial threshold for cleaning the event list. */
54 const typename EventList::size_type CHUNK_INIT_SIZE = 8;
55 /**
56 * Threshold to switch from exponential to linear growth
57 * in the cleanup frequency.
58 */
59 const typename EventList::size_type CHUNK_MAX_SIZE = 128;
60
61 EventList::size_type m_nextCleanupSize; //!< Batch size for cleanup
62 EventList m_events; //!< The tracked event list
63
64 /**
65 * \brief Called when a new event was added and the cleanup limit was
66 * exceeded in consequence.
67 */
68 void Cleanup();
69 /**
70 * \brief Grow the cleanup limit.
71 * Increase the cleanup size by the smaller of
72 * the current cleanup size (exponential growth),
73 * or the CHUNK_MAX_SIZE (linear growth).
74 */
75 void Grow();
76 /**
77 * \brief Shrink the cleanup limit
78 * Reduce the cleanup size by factors of two until less than the
79 * current event list, then Grow one step.
80 */
81 void Shrink();
82};
83
84} // namespace ns3
85
86#endif /* EVENT_GARBAGE_COLLECTOR_H */
An object that tracks scheduled events and automatically cancels them when it is destroyed.
const EventList::size_type CHUNK_INIT_SIZE
Initial threshold for cleaning the event list.
void Track(EventId event)
Tracks a new event.
const EventList::size_type CHUNK_MAX_SIZE
Threshold to switch from exponential to linear growth in the cleanup frequency.
EventList m_events
The tracked event list.
void Cleanup()
Called when a new event was added and the cleanup limit was exceeded in consequence.
EventList::size_type m_nextCleanupSize
Batch size for cleanup.
void Grow()
Grow the cleanup limit.
void Shrink()
Shrink the cleanup limit Reduce the cleanup size by factors of two until less than the current event ...
std::multiset< EventId > EventList
Event list container.
An identifier for simulation events.
Definition event-id.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.