A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
helper
event-garbage-collector.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INESC Porto
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
19
*/
20
#include "
event-garbage-collector.h
"
21
29
namespace
ns3
{
30
31
32
EventGarbageCollector::EventGarbageCollector
()
33
: m_nextCleanupSize (CHUNK_INIT_SIZE),
34
m_events ()
35
{
36
}
37
38
void
39
EventGarbageCollector::Track
(
EventId
event)
40
{
41
m_events
.insert (event);
42
if
(
m_events
.size () >=
m_nextCleanupSize
)
43
Cleanup
();
44
}
45
46
void
47
EventGarbageCollector::Grow
()
48
{
49
m_nextCleanupSize
+= (
m_nextCleanupSize
<
CHUNK_MAX_SIZE
?
50
m_nextCleanupSize
:
CHUNK_MAX_SIZE
);
51
}
52
53
void
54
EventGarbageCollector::Shrink
()
55
{
56
while
(
m_nextCleanupSize
>
m_events
.size ())
57
m_nextCleanupSize
>>= 1;
58
Grow
();
59
}
60
61
// Called when a new event was added and
62
// the cleanup limit was exceeded in consequence.
63
void
64
EventGarbageCollector::Cleanup
()
65
{
66
for
(EventList::iterator iter =
m_events
.begin (); iter !=
m_events
.end ();)
67
{
68
if
((*iter).IsExpired ())
69
{
70
m_events
.erase (iter++);
71
}
72
else
73
break
;
// EventIds are sorted by timestamp => further events are not expired for sure
74
}
75
76
// If after cleanup we are still over the limit, increase the limit.
77
if
(
m_events
.size () >=
m_nextCleanupSize
)
78
Grow
();
79
else
80
Shrink
();
81
}
82
83
84
EventGarbageCollector::~EventGarbageCollector
()
85
{
86
for
(
auto
event :
m_events
)
87
{
88
Simulator::Cancel
(event);
89
}
90
}
91
92
}
// namespace ns3
93
94
ns3::EventGarbageCollector::EventGarbageCollector
EventGarbageCollector()
Definition:
event-garbage-collector.cc:32
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:346
ns3::EventGarbageCollector::Grow
void Grow()
Grow the cleanup limit.
Definition:
event-garbage-collector.cc:47
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:64
event-garbage-collector.h
ns3::EventGarbageCollector declaration.
ns3::EventGarbageCollector::~EventGarbageCollector
~EventGarbageCollector()
Definition:
event-garbage-collector.cc:84
ns3::EventGarbageCollector::m_events
EventList m_events
The tracked event list.
Definition:
event-garbage-collector.h:74
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:71
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::EventId
An identifier for simulation events.
Definition:
event-id.h:53
ns3::EventGarbageCollector::m_nextCleanupSize
EventList::size_type m_nextCleanupSize
Batch size for cleanup.
Definition:
event-garbage-collector.h:73
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition:
event-garbage-collector.cc:39
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
Generated on Wed Nov 7 2018 10:01:49 for ns-3 by
1.8.14