A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
event-garbage-collector.cc
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
#include "
event-garbage-collector.h
"
20
28
namespace
ns3
29
{
30
31
EventGarbageCollector::EventGarbageCollector
()
32
: m_nextCleanupSize(CHUNK_INIT_SIZE),
33
m_events()
34
{
35
}
36
37
void
38
EventGarbageCollector::Track
(
EventId
event)
39
{
40
m_events
.insert(event);
41
if
(
m_events
.size() >=
m_nextCleanupSize
)
42
{
43
Cleanup
();
44
}
45
}
46
47
void
48
EventGarbageCollector::Grow
()
49
{
50
m_nextCleanupSize
+= (
m_nextCleanupSize
<
CHUNK_MAX_SIZE
?
m_nextCleanupSize
:
CHUNK_MAX_SIZE
);
51
}
52
53
void
54
EventGarbageCollector::Shrink
()
55
{
56
while
(
m_nextCleanupSize
>
m_events
.size())
57
{
58
m_nextCleanupSize
>>= 1;
59
}
60
Grow
();
61
}
62
63
// Called when a new event was added and
64
// the cleanup limit was exceeded in consequence.
65
void
66
EventGarbageCollector::Cleanup
()
67
{
68
for
(
auto
iter =
m_events
.begin(); iter !=
m_events
.end();)
69
{
70
if
((*iter).IsExpired())
71
{
72
m_events
.erase(iter++);
73
}
74
else
75
{
76
break
;
// EventIds are sorted by timestamp => further events are not expired for sure
77
}
78
}
79
80
// If after cleanup we are still over the limit, increase the limit.
81
if
(
m_events
.size() >=
m_nextCleanupSize
)
82
{
83
Grow
();
84
}
85
else
86
{
87
Shrink
();
88
}
89
}
90
91
EventGarbageCollector::~EventGarbageCollector
()
92
{
93
for
(
const
auto
& event :
m_events
)
94
{
95
Simulator::Cancel
(event);
96
}
97
}
98
99
}
// namespace ns3
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition:
event-garbage-collector.cc:38
ns3::EventGarbageCollector::CHUNK_MAX_SIZE
const EventList::size_type CHUNK_MAX_SIZE
Threshold to switch from exponential to linear growth in the cleanup frequency.
Definition:
event-garbage-collector.h:70
ns3::EventGarbageCollector::m_events
EventList m_events
The tracked event list.
Definition:
event-garbage-collector.h:73
ns3::EventGarbageCollector::Cleanup
void Cleanup()
Called when a new event was added and the cleanup limit was exceeded in consequence.
Definition:
event-garbage-collector.cc:66
ns3::EventGarbageCollector::m_nextCleanupSize
EventList::size_type m_nextCleanupSize
Batch size for cleanup.
Definition:
event-garbage-collector.h:72
ns3::EventGarbageCollector::Grow
void Grow()
Grow the cleanup limit.
Definition:
event-garbage-collector.cc:48
ns3::EventGarbageCollector::~EventGarbageCollector
~EventGarbageCollector()
Definition:
event-garbage-collector.cc:91
ns3::EventGarbageCollector::Shrink
void Shrink()
Shrink the cleanup limit Reduce the cleanup size by factors of two until less than the current event ...
Definition:
event-garbage-collector.cc:54
ns3::EventGarbageCollector::EventGarbageCollector
EventGarbageCollector()
Definition:
event-garbage-collector.cc:31
ns3::EventId
An identifier for simulation events.
Definition:
event-id.h:55
ns3::Simulator::Cancel
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition:
simulator.cc:285
event-garbage-collector.h
ns3::EventGarbageCollector declaration.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
helper
event-garbage-collector.cc
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1