author | Mitch Watrous <watrous@u.washington.edu> |
Wed, 18 May 2011 17:24:04 -0700 | |
changeset 7241 | 0a7a16b599e8 |
parent 6941 | 9d2c79c992d7 |
child 7386 | 2310ed220a61 |
permissions | -rw-r--r-- |
1671
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
2 |
/* |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
3 |
* Copyright (c) 2007 INESC Porto |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
4 |
* |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
8 |
* |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
13 |
* |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
17 |
* |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
18 |
* Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
19 |
*/ |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
20 |
#ifndef EVENT_GARBAGE_COLLECTOR_H |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
21 |
#define EVENT_GARBAGE_COLLECTOR_H |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
22 |
|
1769
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
23 |
#include <set> |
1768
1664a9db93b9
Make EventGarbageCollector private to the olsr module; adapt olsr to Timer API changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1671
diff
changeset
|
24 |
#include "ns3/event-id.h" |
1664a9db93b9
Make EventGarbageCollector private to the olsr module; adapt olsr to Timer API changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1671
diff
changeset
|
25 |
#include "ns3/simulator.h" |
1671
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
26 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
27 |
namespace ns3 { |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
28 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
29 |
/** |
7241
0a7a16b599e8
Make some more modules show up on doxygen modules page
Mitch Watrous <watrous@u.washington.edu>
parents:
6941
diff
changeset
|
30 |
* \ingroup tools |
0a7a16b599e8
Make some more modules show up on doxygen modules page
Mitch Watrous <watrous@u.washington.edu>
parents:
6941
diff
changeset
|
31 |
* |
1671
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
32 |
* \brief An object that tracks scheduled events and automatically |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
33 |
* cancels them when it is destroyed. It is useful in situations |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
34 |
* where multiple instances of the same type of event can |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
35 |
* simultaneously be scheduled, and when the events should be limited |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
36 |
* to the lifetime of a container object. |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
37 |
*/ |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
38 |
class EventGarbageCollector |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
39 |
{ |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
40 |
public: |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
41 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
42 |
EventGarbageCollector (); |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
43 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
44 |
/** |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
45 |
* \brief Tracks a new event |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
46 |
*/ |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
47 |
void Track (EventId event); |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
48 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
49 |
~EventGarbageCollector (); |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
50 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
51 |
private: |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
52 |
|
1769
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
53 |
struct EventIdLessThanTs |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
54 |
{ |
1770
6d15f1dbfe71
Add a missing const.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1769
diff
changeset
|
55 |
bool operator () (const EventId &a, const EventId &b) const |
1769
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
56 |
{ |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
57 |
return (a.GetTs () < b.GetTs ()); |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
58 |
} |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
59 |
}; |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
60 |
|
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
61 |
typedef std::multiset<EventId, EventIdLessThanTs> EventList; |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
62 |
|
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
63 |
EventList::size_type m_nextCleanupSize; |
0ca4a39dca8b
Optimize EventGarbageCollector by using std::multiset with EventIds sorted by expiration time.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1768
diff
changeset
|
64 |
EventList m_events; |
1671
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
65 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
66 |
void Cleanup (); |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
67 |
void Grow (); |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
68 |
void Shrink (); |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
69 |
}; |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
70 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
71 |
}; // namespace ns3 |
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
72 |
|
878a9e02bcd6
Event Garbage Collector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
73 |
#endif /* EVENT_GARBAGE_COLLECTOR_H */ |