A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
event-garbage-collector.cc
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
#include "
event-garbage-collector.h
"
9
10
/**
11
* \file
12
* \ingroup core-helpers
13
* \ingroup events
14
* ns3::EventGarbageCollector implementation.
15
*/
16
17
namespace
ns3
18
{
19
20
EventGarbageCollector::EventGarbageCollector
()
21
: m_nextCleanupSize(CHUNK_INIT_SIZE),
22
m_events()
23
{
24
}
25
26
void
27
EventGarbageCollector::Track
(
EventId
event)
28
{
29
m_events
.insert(event);
30
if
(
m_events
.size() >=
m_nextCleanupSize
)
31
{
32
Cleanup
();
33
}
34
}
35
36
void
37
EventGarbageCollector::Grow
()
38
{
39
m_nextCleanupSize
+= (
m_nextCleanupSize
<
CHUNK_MAX_SIZE
?
m_nextCleanupSize
:
CHUNK_MAX_SIZE
);
40
}
41
42
void
43
EventGarbageCollector::Shrink
()
44
{
45
while
(
m_nextCleanupSize
>
m_events
.size())
46
{
47
m_nextCleanupSize
>>= 1;
48
}
49
Grow
();
50
}
51
52
// Called when a new event was added and
53
// the cleanup limit was exceeded in consequence.
54
void
55
EventGarbageCollector::Cleanup
()
56
{
57
for
(
auto
iter =
m_events
.begin(); iter !=
m_events
.end();)
58
{
59
if
((*iter).IsExpired())
60
{
61
m_events
.erase(iter++);
62
}
63
else
64
{
65
break
;
// EventIds are sorted by timestamp => further events are not expired for sure
66
}
67
}
68
69
// If after cleanup we are still over the limit, increase the limit.
70
if
(
m_events
.size() >=
m_nextCleanupSize
)
71
{
72
Grow
();
73
}
74
else
75
{
76
Shrink
();
77
}
78
}
79
80
EventGarbageCollector::~EventGarbageCollector
()
81
{
82
for
(
const
auto
& event :
m_events
)
83
{
84
Simulator::Cancel
(event);
85
}
86
}
87
88
}
// namespace ns3
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition
event-garbage-collector.cc:27
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:59
ns3::EventGarbageCollector::m_events
EventList m_events
The tracked event list.
Definition
event-garbage-collector.h:62
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:55
ns3::EventGarbageCollector::m_nextCleanupSize
EventList::size_type m_nextCleanupSize
Batch size for cleanup.
Definition
event-garbage-collector.h:61
ns3::EventGarbageCollector::Grow
void Grow()
Grow the cleanup limit.
Definition
event-garbage-collector.cc:37
ns3::EventGarbageCollector::~EventGarbageCollector
~EventGarbageCollector()
Definition
event-garbage-collector.cc:80
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:43
ns3::EventGarbageCollector::EventGarbageCollector
EventGarbageCollector()
Definition
event-garbage-collector.cc:20
ns3::EventId
An identifier for simulation events.
Definition
event-id.h:45
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:274
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 Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0