author | Peter D. Barnes, Jr. <barnes26@llnl.gov> |
Sun, 07 Dec 2014 22:08:04 -0800 | |
changeset 11096 | e57bfdb4f12c |
parent 10968 | 2d29fee2b7b8 |
child 11131 | 6a448ac28669 |
permissions | -rw-r--r-- |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2007 INRIA, Gustavo Carneiro |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* Authors: Gustavo Carneiro <gjcarneiro@gmail.com>, |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
*/ |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
21 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
22 |
#include "object.h" |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
23 |
#include "object-factory.h" |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
#include "assert.h" |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include "singleton.h" |
2438
e2ac9f9aeeb9
value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2436
diff
changeset
|
26 |
#include "attribute.h" |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1420
diff
changeset
|
27 |
#include "log.h" |
2502
50d0da37f02f
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2489
diff
changeset
|
28 |
#include "string.h" |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
#include <vector> |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
30 |
#include <sstream> |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
31 |
#include <cstdlib> |
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
32 |
#include <cstring> |
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
33 |
|
11096
e57bfdb4f12c
[Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
34 |
/** |
e57bfdb4f12c
[Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
35 |
* \file |
e57bfdb4f12c
[Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
36 |
* \ingroup object |
e57bfdb4f12c
[Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
37 |
* ns3::Object class definition. |
e57bfdb4f12c
[Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
38 |
*/ |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
39 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
40 |
namespace ns3 { |
1374
77468496f7e0
avoid problems with recursive use of Object::DoCollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1372
diff
changeset
|
41 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
42 |
NS_LOG_COMPONENT_DEFINE ("Object"); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
|
2233
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
44 |
/********************************************************************* |
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
45 |
* The Object implementation |
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
46 |
*********************************************************************/ |
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
47 |
|
10652
dc18deba4502
[doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10410
diff
changeset
|
48 |
NS_OBJECT_ENSURE_REGISTERED (Object); |
2247
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
49 |
|
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
50 |
Object::AggregateIterator::AggregateIterator () |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
51 |
: m_object (0), |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
52 |
m_current (0) |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
53 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
54 |
NS_LOG_FUNCTION (this); |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
55 |
} |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
56 |
|
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
57 |
bool |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
58 |
Object::AggregateIterator::HasNext (void) const |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
59 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
60 |
NS_LOG_FUNCTION (this); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
61 |
return m_current < m_object->m_aggregates->n; |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
62 |
} |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
63 |
Ptr<const Object> |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
64 |
Object::AggregateIterator::Next (void) |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
65 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
66 |
NS_LOG_FUNCTION (this); |
5869
67fc4930b470
The iterator needs to actually go forward
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
67 |
Object *object = m_object->m_aggregates->buffer[m_current]; |
67fc4930b470
The iterator needs to actually go forward
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
68 |
m_current++; |
67fc4930b470
The iterator needs to actually go forward
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
69 |
return object; |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
70 |
} |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
71 |
Object::AggregateIterator::AggregateIterator (Ptr<const Object> object) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
72 |
: m_object (object), |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
73 |
m_current (0) |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
74 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
75 |
NS_LOG_FUNCTION (this << object); |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
76 |
} |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
77 |
|
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
78 |
|
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
79 |
TypeId |
2634
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
80 |
Object::GetInstanceTypeId (void) const |
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
81 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
82 |
NS_LOG_FUNCTION (this); |
2636
fe664ae9aa8b
return the _current_ tid, not the Object tid.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2635
diff
changeset
|
83 |
return m_tid; |
2634
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
84 |
} |
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
85 |
|
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
86 |
TypeId |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
87 |
Object::GetTypeId (void) |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
88 |
{ |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
89 |
static TypeId tid = TypeId ("ns3::Object") |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
90 |
.SetParent<ObjectBase> () |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
91 |
; |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
92 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
93 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
94 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
95 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
96 |
Object::Object () |
5486
9bf34ba759a3
Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5479
diff
changeset
|
97 |
: m_tid (Object::GetTypeId ()), |
713
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
98 |
m_disposed (false), |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
99 |
m_initialized (false), |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
100 |
m_aggregates ((struct Aggregates *) std::malloc (sizeof (struct Aggregates))), |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
101 |
m_getObjectCount (0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
102 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
103 |
NS_LOG_FUNCTION (this); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
104 |
m_aggregates->n = 1; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
105 |
m_aggregates->buffer[0] = this; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
106 |
} |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
107 |
Object::~Object () |
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
108 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
109 |
// remove this object from the aggregate list |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
110 |
NS_LOG_FUNCTION (this); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
111 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
112 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
113 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
114 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
115 |
if (current == this) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
116 |
{ |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
117 |
std::memmove (&m_aggregates->buffer[i], |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
118 |
&m_aggregates->buffer[i+1], |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
119 |
sizeof (Object *)*(m_aggregates->n - (i+1))); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
120 |
m_aggregates->n--; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
121 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
122 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
123 |
// finally, if all objects have been removed from the list, |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
124 |
// delete the aggregate list |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
125 |
if (m_aggregates->n == 0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
126 |
{ |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
127 |
std::free (m_aggregates); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
128 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
129 |
m_aggregates = 0; |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
130 |
} |
2667
2324032b8f90
Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
131 |
Object::Object (const Object &o) |
5486
9bf34ba759a3
Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5479
diff
changeset
|
132 |
: m_tid (o.m_tid), |
2667
2324032b8f90
Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
133 |
m_disposed (false), |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
134 |
m_initialized (false), |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
135 |
m_aggregates ((struct Aggregates *) std::malloc (sizeof (struct Aggregates))), |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
136 |
m_getObjectCount (0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
137 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
138 |
m_aggregates->n = 1; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
139 |
m_aggregates->buffer[0] = this; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
140 |
} |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
141 |
void |
7399
520706f801e8
introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents:
7169
diff
changeset
|
142 |
Object::Construct (const AttributeConstructionList &attributes) |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
143 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
144 |
NS_LOG_FUNCTION (this << &attributes); |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
145 |
ConstructSelf (attributes); |
2569
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2542
diff
changeset
|
146 |
} |
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2460
diff
changeset
|
147 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
148 |
Ptr<Object> |
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
149 |
Object::DoGetObject (TypeId tid) const |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
150 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
151 |
NS_LOG_FUNCTION (this << tid); |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
152 |
NS_ASSERT (CheckLoose ()); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
153 |
|
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
154 |
uint32_t n = m_aggregates->n; |
3871
c6f693de286d
5% cpu optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3397
diff
changeset
|
155 |
TypeId objectTid = Object::GetTypeId (); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
156 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
157 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
158 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
159 |
TypeId cur = current->GetInstanceTypeId (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
160 |
while (cur != tid && cur != objectTid) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
161 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
162 |
cur = cur.GetParent (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
163 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
164 |
if (cur == tid) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
165 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
166 |
// This is an attempt to 'cache' the result of this lookup. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
167 |
// the idea is that if we perform a lookup for a TypeId on this object, |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
168 |
// we are likely to perform the same lookup later so, we make sure |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
169 |
// that the aggregate array is sorted by the number of accesses |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
170 |
// to each object. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
171 |
|
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
172 |
// first, increment the access count |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
173 |
current->m_getObjectCount++; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
174 |
// then, update the sort |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
175 |
UpdateSortedArray (m_aggregates, i); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
176 |
// finally, return the match |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
177 |
return const_cast<Object *> (current); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
178 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
179 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
180 |
return 0; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
181 |
} |
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
182 |
void |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
183 |
Object::Initialize (void) |
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
184 |
{ |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
185 |
/** |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
186 |
* Note: the code here is a bit tricky because we need to protect ourselves from |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
187 |
* modifications in the aggregate array while DoInitialize is called. The user's |
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
188 |
* implementation of the DoInitialize method could call GetObject (which could |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
189 |
* reorder the array) and it could call AggregateObject which would add an |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
190 |
* object at the end of the array. To be safe, we restart iteration over the |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
191 |
* array whenever we call some user code, just in case. |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
192 |
*/ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
193 |
NS_LOG_FUNCTION (this); |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
194 |
restart: |
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
195 |
uint32_t n = m_aggregates->n; |
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
196 |
for (uint32_t i = 0; i < n; i++) |
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
197 |
{ |
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
198 |
Object *current = m_aggregates->buffer[i]; |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
199 |
if (!current->m_initialized) |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
200 |
{ |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
201 |
current->DoInitialize (); |
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
202 |
current->m_initialized = true; |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
203 |
goto restart; |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
204 |
} |
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
205 |
} |
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
206 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
207 |
void |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
208 |
Object::Dispose (void) |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
209 |
{ |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
210 |
/** |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
211 |
* Note: the code here is a bit tricky because we need to protect ourselves from |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
212 |
* modifications in the aggregate array while DoDispose is called. The user's |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
213 |
* DoDispose implementation could call GetObject (which could reorder the array) |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
214 |
* and it could call AggregateObject which would add an object at the end of the array. |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
215 |
* So, to be safe, we restart the iteration over the array whenever we call some |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
216 |
* user code. |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
217 |
*/ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
218 |
NS_LOG_FUNCTION (this); |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7003
diff
changeset
|
219 |
restart: |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
220 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
221 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
222 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
223 |
Object *current = m_aggregates->buffer[i]; |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
224 |
if (!current->m_disposed) |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
225 |
{ |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
226 |
current->DoDispose (); |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
227 |
current->m_disposed = true; |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
228 |
goto restart; |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
229 |
} |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
230 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
231 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
232 |
void |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
233 |
Object::UpdateSortedArray (struct Aggregates *aggregates, uint32_t j) const |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
234 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
235 |
NS_LOG_FUNCTION (this << aggregates << j); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
236 |
while (j > 0 && |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
237 |
aggregates->buffer[j]->m_getObjectCount > aggregates->buffer[j-1]->m_getObjectCount) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
238 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
239 |
Object *tmp = aggregates->buffer[j-1]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
240 |
aggregates->buffer[j-1] = aggregates->buffer[j]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
241 |
aggregates->buffer[j] = tmp; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
242 |
j--; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
243 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
244 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
245 |
void |
2258
666099a753e0
AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
246 |
Object::AggregateObject (Ptr<Object> o) |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
247 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
248 |
NS_LOG_FUNCTION (this << o); |
718 | 249 |
NS_ASSERT (!m_disposed); |
250 |
NS_ASSERT (!o->m_disposed); |
|
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
251 |
NS_ASSERT (CheckLoose ()); |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
252 |
NS_ASSERT (o->CheckLoose ()); |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
253 |
|
3397
cad55f67f3fc
avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3394
diff
changeset
|
254 |
if (DoGetObject (o->GetInstanceTypeId ())) |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
255 |
{ |
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
256 |
NS_FATAL_ERROR ("Object::AggregateObject(): " |
3397
cad55f67f3fc
avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3394
diff
changeset
|
257 |
"Multiple aggregation of objects of type " << |
cad55f67f3fc
avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3394
diff
changeset
|
258 |
o->GetInstanceTypeId ().GetName ()); |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
259 |
} |
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
260 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
261 |
Object *other = PeekPointer (o); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
262 |
// first create the new aggregate buffer. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
263 |
uint32_t total = m_aggregates->n + other->m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
264 |
struct Aggregates *aggregates = |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
265 |
(struct Aggregates *)std::malloc (sizeof(struct Aggregates)+(total-1)*sizeof(Object*)); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
266 |
aggregates->n = total; |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
267 |
|
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
268 |
// copy our buffer to the new buffer |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
269 |
std::memcpy (&aggregates->buffer[0], |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
270 |
&m_aggregates->buffer[0], |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
271 |
m_aggregates->n*sizeof(Object*)); |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
272 |
|
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
273 |
// append the other buffer into the new buffer too |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
274 |
for (uint32_t i = 0; i < other->m_aggregates->n; i++) |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
275 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
276 |
aggregates->buffer[m_aggregates->n+i] = other->m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
277 |
UpdateSortedArray (aggregates, m_aggregates->n + i); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
278 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
279 |
|
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
280 |
// keep track of the old aggregate buffers for the iteration |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
281 |
// of NotifyNewAggregates |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
282 |
struct Aggregates *a = m_aggregates; |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
283 |
struct Aggregates *b = other->m_aggregates; |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
284 |
|
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
285 |
// Then, assign the new aggregation buffer to every object |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
286 |
uint32_t n = aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
287 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
288 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
289 |
Object *current = aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
290 |
current->m_aggregates = aggregates; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
291 |
} |
5486
9bf34ba759a3
Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5479
diff
changeset
|
292 |
|
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
293 |
// Finally, call NotifyNewAggregate on all the objects aggregates together. |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
294 |
// We purposedly use the old aggregate buffers to iterate over the objects |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
295 |
// because this allows us to assume that they will not change from under |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
296 |
// our feet, even if our users call AggregateObject from within their |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
297 |
// NotifyNewAggregate method. |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
298 |
for (uint32_t i = 0; i < a->n; i++) |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
299 |
{ |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
300 |
Object *current = a->buffer[i]; |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
301 |
current->NotifyNewAggregate (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
302 |
} |
5758
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
303 |
for (uint32_t i = 0; i < b->n; i++) |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
304 |
{ |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
305 |
Object *current = b->buffer[i]; |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
306 |
current->NotifyNewAggregate (); |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
307 |
} |
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
308 |
|
bac30d4b6115
Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5524
diff
changeset
|
309 |
// Now that we are done with them, we can free our old aggregate buffers |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
310 |
std::free (a); |
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
7399
diff
changeset
|
311 |
std::free (b); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
312 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
313 |
/** |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
314 |
* This function must be implemented in the stack that needs to notify |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
315 |
* other stacks connected to the node of their presence in the node. |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
316 |
*/ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
317 |
void |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
318 |
Object::NotifyNewAggregate () |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
319 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
320 |
NS_LOG_FUNCTION (this); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
321 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
322 |
|
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
323 |
Object::AggregateIterator |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
324 |
Object::GetAggregateIterator (void) const |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
325 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
326 |
NS_LOG_FUNCTION (this); |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
327 |
return AggregateIterator (this); |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
328 |
} |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
329 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
330 |
void |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
331 |
Object::SetTypeId (TypeId tid) |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
332 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
333 |
NS_LOG_FUNCTION (this << tid); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
334 |
NS_ASSERT (Check ()); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
335 |
m_tid = tid; |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
336 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
337 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
338 |
void |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
339 |
Object::DoDispose (void) |
713
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
340 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
341 |
NS_LOG_FUNCTION (this); |
713
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
342 |
NS_ASSERT (!m_disposed); |
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
343 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
344 |
|
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
345 |
void |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
346 |
Object::DoInitialize (void) |
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
347 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
348 |
NS_LOG_FUNCTION (this); |
9703
681f35b212ff
Rename Start and DoStart methods to Initialize and DoInitialize
Vedran Miletić <rivanvx@gmail.com>
parents:
9193
diff
changeset
|
349 |
NS_ASSERT (!m_initialized); |
5524
efed7493f2c1
Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents:
5490
diff
changeset
|
350 |
} |
1336
de5a133ece8a
add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
732
diff
changeset
|
351 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
352 |
bool |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
353 |
Object::Check (void) const |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
354 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
355 |
NS_LOG_FUNCTION (this); |
5486
9bf34ba759a3
Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5479
diff
changeset
|
356 |
return (GetReferenceCount () > 0); |
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
357 |
} |
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
358 |
|
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
359 |
/* In some cases, when an event is scheduled against a subclass of |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
360 |
* Object, and if no one owns a reference directly to this object, the |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
361 |
* object is alive, has a refcount of zero and the method ran when the |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
362 |
* event expires runs against the raw pointer which means that we are |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
363 |
* manipulating an object with a refcount of zero. So, instead we |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
364 |
* check the aggregate reference count. |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
365 |
*/ |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
366 |
bool |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
367 |
Object::CheckLoose (void) const |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
368 |
{ |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
369 |
NS_LOG_FUNCTION (this); |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
370 |
uint32_t refcount = 0; |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
371 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
372 |
for (uint32_t i = 0; i < n; i++) |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
373 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
374 |
Object *current = m_aggregates->buffer[i]; |
11096
e57bfdb4f12c
[Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10968
diff
changeset
|
375 |
/// \todo Shortcircuit this loop. |
5486
9bf34ba759a3
Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5479
diff
changeset
|
376 |
refcount += current->GetReferenceCount (); |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
377 |
} |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
378 |
return (refcount > 0); |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
379 |
} |
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
380 |
void |
5486
9bf34ba759a3
Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5479
diff
changeset
|
381 |
Object::DoDelete (void) |
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
382 |
{ |
5840
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
383 |
// check if we really need to die |
9134
7a750f032acd
Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents:
9063
diff
changeset
|
384 |
NS_LOG_FUNCTION (this); |
5840
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
385 |
for (uint32_t i = 0; i < m_aggregates->n; i++) |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
386 |
{ |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
387 |
Object *current = m_aggregates->buffer[i]; |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
388 |
if (current->GetReferenceCount () > 0) |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
389 |
{ |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
390 |
return; |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
391 |
} |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
392 |
} |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
393 |
|
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
394 |
// Now, we know that we are alone to use this aggregate so, |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
395 |
// we can dispose and delete everything safely. |
c2b3762932e8
get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5758
diff
changeset
|
396 |
|
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
397 |
uint32_t n = m_aggregates->n; |
2529
d5f8bee5fcbd
ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2523
diff
changeset
|
398 |
// Ensure we are disposed. |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
399 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
400 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
401 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
402 |
if (!current->m_disposed) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
403 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
404 |
current->DoDispose (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
405 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
406 |
} |
2529
d5f8bee5fcbd
ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2523
diff
changeset
|
407 |
|
5490
0883c01e3ed7
delete dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5486
diff
changeset
|
408 |
// Now, actually delete all objects |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
409 |
struct Aggregates *aggregates = m_aggregates; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
410 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
411 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
412 |
// There is a trick here: each time we call delete below, |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
413 |
// the deleted object is removed from the aggregate buffer |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
414 |
// in the destructor so, the index of the next element to |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
415 |
// lookup is always zero |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
416 |
Object *current = aggregates->buffer[0]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
417 |
delete current; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
418 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
419 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
420 |
} // namespace ns3 |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
421 |