A Discrete-Event Network Simulator
API
 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  */
21 
22 #define CLEANUP_CHUNK_MIN_SIZE 8
23 #define CLEANUP_CHUNK_MAX_SIZE 128
24 
25 
26 namespace ns3 {
27 
28 
30  m_nextCleanupSize (CLEANUP_CHUNK_MIN_SIZE)
31 {
32 }
33 
34 void
36 {
37  m_events.insert (event);
38  if (m_events.size () >= m_nextCleanupSize)
39  Cleanup ();
40 }
41 
42 void
44 {
47 }
48 
49 void
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
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 
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 
#define CLEANUP_CHUNK_MIN_SIZE
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
#define CLEANUP_CHUNK_MAX_SIZE
an identifier for simulation events.
Definition: event-id.h:46
EventList::size_type m_nextCleanupSize
void Track(EventId event)
Tracks a new event.