A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
22
#define CLEANUP_CHUNK_MIN_SIZE 8
23
#define CLEANUP_CHUNK_MAX_SIZE 128
24
25
26
namespace
ns3 {
27
28
29
EventGarbageCollector::EventGarbageCollector
() :
30
m_nextCleanupSize (
CLEANUP_CHUNK_MIN_SIZE
)
31
{
32
}
33
34
void
35
EventGarbageCollector::Track
(
EventId
event)
36
{
37
m_events
.insert (event);
38
if
(
m_events
.size () >=
m_nextCleanupSize
)
39
Cleanup
();
40
}
41
42
void
43
EventGarbageCollector::Grow
()
44
{
45
m_nextCleanupSize
+= (
m_nextCleanupSize
<
CLEANUP_CHUNK_MAX_SIZE
?
46
m_nextCleanupSize
:
CLEANUP_CHUNK_MAX_SIZE
);
47
}
48
49
void
50
EventGarbageCollector::Shrink
()
51
{
52
while
(
m_nextCleanupSize
>
m_events
.size ())
53
m_nextCleanupSize
>>= 1;
54
Grow
();
55
}
56
57
// Called when a new event was added and the cleanup limit was exceeded in consequence.
58
void
59
EventGarbageCollector::Cleanup
()
60
{
61
for
(EventList::iterator iter =
m_events
.begin (); iter !=
m_events
.end ();)
62
{
63
if
((*iter).IsExpired ())
64
{
65
m_events
.erase (iter++);
66
}
67
else
68
break
;
// EventIds are sorted by timestamp => further events are not expired for sure
69
}
70
71
// If after cleanup we are still over the limit, increase the limit.
72
if
(
m_events
.size () >=
m_nextCleanupSize
)
73
Grow
();
74
else
75
Shrink
();
76
}
77
78
79
EventGarbageCollector::~EventGarbageCollector
()
80
{
81
for
(EventList::iterator event =
m_events
.begin ();
82
event
!=
m_events
.end ();
event
++)
83
{
84
Simulator::Cancel
(*event);
85
}
86
}
87
88
}
// namespace ns3
89
90
ns3::EventGarbageCollector::EventGarbageCollector
EventGarbageCollector()
Definition:
event-garbage-collector.cc:29
CLEANUP_CHUNK_MIN_SIZE
#define CLEANUP_CHUNK_MIN_SIZE
Definition:
event-garbage-collector.cc:22
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:268
ns3::EventGarbageCollector::Grow
void Grow()
Definition:
event-garbage-collector.cc:43
ns3::EventGarbageCollector::Cleanup
void Cleanup()
Definition:
event-garbage-collector.cc:59
event-garbage-collector.h
CLEANUP_CHUNK_MAX_SIZE
#define CLEANUP_CHUNK_MAX_SIZE
Definition:
event-garbage-collector.cc:23
ns3::EventGarbageCollector::~EventGarbageCollector
~EventGarbageCollector()
Definition:
event-garbage-collector.cc:79
ns3::EventGarbageCollector::m_events
EventList m_events
Definition:
event-garbage-collector.h:64
ns3::EventId
an identifier for simulation events.
Definition:
event-id.h:46
ns3::EventGarbageCollector::m_nextCleanupSize
EventList::size_type m_nextCleanupSize
Definition:
event-garbage-collector.h:63
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition:
event-garbage-collector.cc:35
ns3::EventGarbageCollector::Shrink
void Shrink()
Definition:
event-garbage-collector.cc:50
src
core
helper
event-garbage-collector.cc
Generated on Sat Apr 19 2014 14:06:51 for ns-3 by
1.8.6