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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
18 */
19#ifndef EVENT_GARBAGE_COLLECTOR_H
20#define EVENT_GARBAGE_COLLECTOR_H
21
22#include "ns3/event-id.h"
23#include "ns3/simulator.h"
24
25#include <set>
26
27/**
28 * \file
29 * \ingroup events
30 * \ingroup core-helpers
31 * ns3::EventGarbageCollector declaration.
32 */
33
34namespace ns3
35{
36
37/**
38 * \ingroup events
39 * \ingroup core-helpers
40 *
41 * \brief An object that tracks scheduled events and automatically
42 * cancels them when it is destroyed. It is useful in situations
43 * where multiple instances of the same type of event can
44 * simultaneously be scheduled, and when the events should be limited
45 * to the lifetime of a container object.
46 */
48{
49 public:
51
52 /**
53 * \brief Tracks a new event
54 * \param [in] event the Event to track
55 */
56 void Track(EventId event);
57
59
60 private:
61 /** Event list container */
62 typedef std::multiset<EventId> EventList;
63
64 /** Initial threshold for cleaning the event list. */
65 const typename EventList::size_type CHUNK_INIT_SIZE = 8;
66 /**
67 * Threshold to switch from exponential to linear growth
68 * in the cleanup frequency.
69 */
70 const typename EventList::size_type CHUNK_MAX_SIZE = 128;
71
72 EventList::size_type m_nextCleanupSize; //!< Batch size for cleanup
73 EventList m_events; //!< The tracked event list
74
75 /**
76 * \brief Called when a new event was added and the cleanup limit was
77 * exceeded in consequence.
78 */
79 void Cleanup();
80 /**
81 * \brief Grow the cleanup limit.
82 * Increase the cleanup size by the smaller of
83 * the current cleanup size (exponential growth),
84 * or the CHUNK_MAX_SIZE (linear growth).
85 */
86 void Grow();
87 /**
88 * \brief Shrink the cleanup limit
89 * Reduce the cleanup size by factors of two until less than the
90 * current event list, then Grow one step.
91 */
92 void Shrink();
93};
94
95} // namespace ns3
96
97#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:55
Every class exported by the ns3 library is enclosed in the ns3 namespace.