From 1668a400c9624cafc3b89ac35d9db1780ac52f96 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 12 Nov 2009 13:01:01 +0100 Subject: [PATCH] replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations. --- src/applications/radvd/radvd-interface.h | 4 +- src/applications/radvd/radvd-prefix.h | 3 +- src/common/ascii-writer.h | 4 +- src/common/packet.cc | 30 +---- src/common/packet.h | 6 +- src/contrib/flow-monitor/flow-classifier.cc | 2 + src/contrib/flow-monitor/flow-classifier.h | 5 +- src/contrib/flow-monitor/flow-probe.h | 6 +- src/contrib/flow-monitor/ipv4-flow-probe.h | 2 +- src/core/attribute.h | 8 +- src/core/callback.h | 17 +-- src/core/ref-count-base.cc | 46 +------- src/core/ref-count-base.h | 64 ++--------- src/core/simple-ref-count.h | 103 ++++++++++++++++++ src/core/system-thread.h | 35 +----- src/core/trace-source-accessor.cc | 15 --- src/core/trace-source-accessor.h | 7 +- src/core/unix-system-thread.cc | 3 +- src/core/wscript | 1 + .../mesh/dot11s/ie-dot11s-beacon-timing.h | 2 +- src/devices/mesh/dot11s/ie-dot11s-preq.h | 2 +- .../mesh/mesh-wifi-interface-mac-plugin.h | 4 +- .../mesh/wifi-information-element-vector.cc | 4 + .../mesh/wifi-information-element-vector.h | 4 +- src/devices/wifi/interference-helper.h | 6 +- src/node/ipv4-route.h | 8 +- src/node/ipv6-route.h | 6 +- src/node/packetbb.cc | 74 +------------ src/node/packetbb.h | 35 +----- src/simulator/event-impl.cc | 4 +- src/simulator/event-impl.h | 27 +---- 31 files changed, 177 insertions(+), 360 deletions(-) create mode 100644 src/core/simple-ref-count.h diff --git a/src/applications/radvd/radvd-interface.h b/src/applications/radvd/radvd-interface.h index a53175cef..046c9b6e4 100644 --- a/src/applications/radvd/radvd-interface.h +++ b/src/applications/radvd/radvd-interface.h @@ -22,7 +22,7 @@ #define RADVD_INTERFACE_H #include - +#include "ns3/simple-ref-count.h" #include "radvd-prefix.h" namespace ns3 @@ -33,7 +33,7 @@ namespace ns3 * \class RadvdInterface * \brief Radvd interface configuration. */ -class RadvdInterface : public RefCountBase +class RadvdInterface : public SimpleRefCount { public: /** diff --git a/src/applications/radvd/radvd-prefix.h b/src/applications/radvd/radvd-prefix.h index 2c1433e84..70b02806a 100644 --- a/src/applications/radvd/radvd-prefix.h +++ b/src/applications/radvd/radvd-prefix.h @@ -24,6 +24,7 @@ #include #include "ns3/ipv6-address.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -33,7 +34,7 @@ namespace ns3 * \class RadvdPrefix * \brief Router prefix for radvd application. */ -class RadvdPrefix : public RefCountBase +class RadvdPrefix : public SimpleRefCount { public: /** diff --git a/src/common/ascii-writer.h b/src/common/ascii-writer.h index 03cdc7cf4..648832438 100644 --- a/src/common/ascii-writer.h +++ b/src/common/ascii-writer.h @@ -23,7 +23,7 @@ #include #include -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" #include "ns3/ptr.h" namespace ns3 { @@ -35,7 +35,7 @@ class Packet; * * \brief Ascii output */ -class AsciiWriter : public RefCountBase +class AsciiWriter : public SimpleRefCount { public: static Ptr Get (std::ostream &os); diff --git a/src/common/packet.cc b/src/common/packet.cc index 9741662c4..244c26e6f 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -112,21 +112,6 @@ PacketTagIterator::Item::GetTag (Tag &tag) const } -void -Packet::Ref (void) const -{ - m_refCount++; -} -void -Packet::Unref (void) const -{ - m_refCount--; - if (m_refCount == 0) - { - delete this; - } -} - Ptr Packet::Copy (void) const { @@ -141,8 +126,7 @@ Packet::Packet () m_byteTagList (), m_packetTagList (), m_metadata (m_globalUid, 0), - m_nixVector (0), - m_refCount (1) + m_nixVector (0) { m_globalUid++; } @@ -151,8 +135,7 @@ Packet::Packet (const Packet &o) : m_buffer (o.m_buffer), m_byteTagList (o.m_byteTagList), m_packetTagList (o.m_packetTagList), - m_metadata (o.m_metadata), - m_refCount (1) + m_metadata (o.m_metadata) { o.m_nixVector ? m_nixVector = o.m_nixVector->Copy () : m_nixVector = 0; @@ -179,8 +162,7 @@ Packet::Packet (uint32_t size) m_byteTagList (), m_packetTagList (), m_metadata (m_globalUid, size), - m_nixVector (0), - m_refCount (1) + m_nixVector (0) { m_globalUid++; } @@ -189,8 +171,7 @@ Packet::Packet (uint8_t const*buffer, uint32_t size) m_byteTagList (), m_packetTagList (), m_metadata (m_globalUid, size), - m_nixVector (0), - m_refCount (1) + m_nixVector (0) { m_globalUid++; m_buffer.AddAtStart (size); @@ -204,8 +185,7 @@ Packet::Packet (const Buffer &buffer, const ByteTagList &byteTagList, m_byteTagList (byteTagList), m_packetTagList (packetTagList), m_metadata (metadata), - m_nixVector (0), - m_refCount (1) + m_nixVector (0) {} Ptr diff --git a/src/common/packet.h b/src/common/packet.h index 87add7437..77841235f 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -198,12 +198,9 @@ private: * The performance aspects of the Packet API are discussed in * \ref packetperf */ -class Packet +class Packet : public SimpleRefCount { public: - void Ref (void) const; - void Unref (void) const; - Ptr Copy (void) const; /** @@ -540,7 +537,6 @@ private: /* Please see comments above about nix-vector */ Ptr m_nixVector; - mutable uint32_t m_refCount; static uint32_t m_globalUid; }; diff --git a/src/contrib/flow-monitor/flow-classifier.cc b/src/contrib/flow-monitor/flow-classifier.cc index fb184101f..287e5bfbe 100644 --- a/src/contrib/flow-monitor/flow-classifier.cc +++ b/src/contrib/flow-monitor/flow-classifier.cc @@ -28,6 +28,8 @@ FlowClassifier::FlowClassifier () { } +FlowClassifier::~FlowClassifier () +{} FlowId FlowClassifier::GetNewFlowId () diff --git a/src/contrib/flow-monitor/flow-classifier.h b/src/contrib/flow-monitor/flow-classifier.h index fca1c865c..5bf08fd2a 100644 --- a/src/contrib/flow-monitor/flow-classifier.h +++ b/src/contrib/flow-monitor/flow-classifier.h @@ -21,7 +21,7 @@ #ifndef __FLOW_CLASSIFIER_H__ #define __FLOW_CLASSIFIER_H__ -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" #include namespace ns3 { @@ -39,13 +39,14 @@ typedef uint32_t FlowPacketId; /// statistics reference only those abstract identifiers in order to /// keep the core architecture generic and not tied down to any /// particular flow capture method or classification system. -class FlowClassifier : public RefCountBase +class FlowClassifier : public SimpleRefCount { FlowId m_lastNewFlowId; public: FlowClassifier (); + virtual ~FlowClassifier (); virtual void SerializeToXmlStream (std::ostream &os, int indent) const = 0; diff --git a/src/contrib/flow-monitor/flow-probe.h b/src/contrib/flow-monitor/flow-probe.h index f5857a0e6..faacd1e37 100644 --- a/src/contrib/flow-monitor/flow-probe.h +++ b/src/contrib/flow-monitor/flow-probe.h @@ -24,7 +24,7 @@ #include #include -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" #include "ns3/flow-classifier.h" #include "ns3/nstime.h" @@ -36,14 +36,14 @@ class FlowMonitor; /// in a specific point of the simulated space, report those events to /// the global FlowMonitor, and collect its own flow statistics /// regarding only the packets that pass through that probe. -class FlowProbe : public RefCountBase +class FlowProbe : public SimpleRefCount { protected: FlowProbe (Ptr flowMonitor); public: - ~FlowProbe (); + virtual ~FlowProbe (); struct FlowStats { diff --git a/src/contrib/flow-monitor/ipv4-flow-probe.h b/src/contrib/flow-monitor/ipv4-flow-probe.h index 686516002..5bde99f63 100644 --- a/src/contrib/flow-monitor/ipv4-flow-probe.h +++ b/src/contrib/flow-monitor/ipv4-flow-probe.h @@ -41,7 +41,7 @@ class Ipv4FlowProbe : public FlowProbe public: Ipv4FlowProbe (Ptr monitor, Ptr classifier, Ptr node); - ~Ipv4FlowProbe (); + virtual ~Ipv4FlowProbe (); /// \brief enumeration of possible reasons why a packet may be dropped enum DropReason diff --git a/src/core/attribute.h b/src/core/attribute.h index 2ba5ab1f3..dd1a5cd05 100644 --- a/src/core/attribute.h +++ b/src/core/attribute.h @@ -23,7 +23,7 @@ #include #include #include "ptr.h" -#include "ref-count-base.h" +#include "simple-ref-count.h" namespace ns3 { @@ -48,7 +48,7 @@ class ObjectBase; * Most subclasses of this base class are implemented by the * ATTRIBUTE_HELPER_* macros. */ -class AttributeValue : public RefCountBase +class AttributeValue : public SimpleRefCount { public: AttributeValue (); @@ -94,7 +94,7 @@ public: * of this base class are usually provided through the MakeAccessorHelper * template functions, hidden behind an ATTRIBUTE_HELPER_* macro. */ -class AttributeAccessor : public RefCountBase +class AttributeAccessor : public SimpleRefCount { public: AttributeAccessor (); @@ -146,7 +146,7 @@ public: * Most subclasses of this base class are implemented by the * ATTRIBUTE_HELPER_HEADER and ATTRIBUTE_HELPER_CPP macros. */ -class AttributeChecker : public RefCountBase +class AttributeChecker : public SimpleRefCount { public: AttributeChecker (); diff --git a/src/core/callback.h b/src/core/callback.h index eb4729a39..e09de6750 100644 --- a/src/core/callback.h +++ b/src/core/callback.h @@ -27,6 +27,7 @@ #include "type-traits.h" #include "attribute.h" #include "attribute-helper.h" +#include "simple-ref-count.h" #include namespace ns3 { @@ -72,25 +73,11 @@ struct CallbackTraits } }; -class CallbackImplBase +class CallbackImplBase : public SimpleRefCount { public: - CallbackImplBase () - : m_count (1) {} virtual ~CallbackImplBase () {} - void Ref (void) const { - m_count++; - } - void Unref (void) const { - m_count--; - if (m_count == 0) { - delete this; - } - } - uint32_t GetReferenceCount (void) const { return m_count; } virtual bool IsEqual (Ptr other) const = 0; -private: - mutable uint32_t m_count; }; // declare the CallbackImpl class diff --git a/src/core/ref-count-base.cc b/src/core/ref-count-base.cc index 06abf7c22..c89cc6a83 100644 --- a/src/core/ref-count-base.cc +++ b/src/core/ref-count-base.cc @@ -1,52 +1,8 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 Georgia Tech Research Corporation - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: George Riley - * Adapted from original code in object.h by: - * Authors: Gustavo Carneiro , - * Mathieu Lacage - */ - #include "ref-count-base.h" namespace ns3 { -RefCountBase::RefCountBase() - : m_count (1) -{ -} - -RefCountBase::RefCountBase (const RefCountBase &o) - : m_count (1) +RefCountBase::~RefCountBase () {} -RefCountBase & -RefCountBase::operator = (const RefCountBase &o) -{ - return *this; -} - -RefCountBase::~RefCountBase () -{ -} - -uint32_t -RefCountBase::GetReferenceCount (void) const -{ - return m_count; -} } // namespace ns3 diff --git a/src/core/ref-count-base.h b/src/core/ref-count-base.h index 08e9946fa..3663698ca 100644 --- a/src/core/ref-count-base.h +++ b/src/core/ref-count-base.h @@ -23,74 +23,26 @@ #ifndef __REF_COUNT_BASE_H__ #define __REF_COUNT_BASE_H__ -#include +#include "simple-ref-count.h" namespace ns3 { /** - * \brief a base class that provides implementations of reference counting - * operations. - * - * A base class that provides implementations of reference counting - * operations, for classes that wish to use the templatized smart - * pointer for memory management but that do not wish to derive from - * class ns3::Object. + * \brief A deprecated way to get reference-counting powers * + * Users who wish to use reference counting for a class of their own should use + * instead the template \ref ns3::SimpleRefCount. This class is maintained + * purely for compatibility to avoid breaking the code of users. */ -class RefCountBase +class RefCountBase : public SimpleRefCount { public: - RefCountBase(); - RefCountBase (const RefCountBase &o); - RefCountBase &operator = (const RefCountBase &o); - virtual ~RefCountBase (); /** - * Increment the reference count. This method should not be called - * by user code. RefCountBase instances are expected to be used in - * conjunction with the Ptr template which would make calling Ref - * unecessary and dangerous. + * This only thing this class does it declare a virtual destructor */ - inline void Ref (void) const; - /** - * Decrement the reference count. This method should not be called - * by user code. RefCountBase instances are expected to be used in - * conjunction with the Ptr template which would make calling Ref - * unecessary and dangerous. - */ - inline void Unref (void) const; - - /** - * Get the reference count of the object. Normally not needed; for language bindings. - */ - uint32_t GetReferenceCount (void) const; - -private: - // Note we make this mutable so that the const methods can still - // change it. - mutable uint32_t m_count; // Reference count + virtual ~RefCountBase () = 0; }; } // namespace ns3 -namespace ns3 { - -// Implementation of the in-line methods -void -RefCountBase::Ref (void) const -{ - m_count++; -} - -void -RefCountBase::Unref (void) const -{ - m_count--; - if (m_count == 0) - { // All references removed, ok to delete - delete this; - } -} - -} // namespace ns3 - #endif /* __REF_COUNT_BASE_H__*/ diff --git a/src/core/simple-ref-count.h b/src/core/simple-ref-count.h new file mode 100644 index 000000000..69625968e --- /dev/null +++ b/src/core/simple-ref-count.h @@ -0,0 +1,103 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 Georgia Tech Research Corporation, INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: George Riley + * Gustavo Carneiro , + * Mathieu Lacage + */ +#ifndef SIMPLE_REF_COUNT_H +#define SIMPLE_REF_COUNT_H + +#include "empty.h" +#include + +namespace ns3 { + +/** + * \brief A template-based reference counting class + * + * This template can be used to give reference-counting powers + * to a class. This template does not require this class to + * have a virtual destructor or no parent class. + * + * Note: if you are moving to this template from the RefCountBase class, + * you need to be careful to mark appropriately your destructor virtual + * if needed. i.e., if your class has subclasses, _do_ mark your destructor + * virtual. + * + * \internal + * Note: we rely on the fairly common EBCO (empty base class optimization) + * to get rid of the empty parent when the user does not provide + * a non-trivial parent. + */ +template +class SimpleRefCount : public PARENT +{ +public: + SimpleRefCount () + : m_count (1) + {} + SimpleRefCount (const SimpleRefCount &o) + : m_count (1) + {} + SimpleRefCount &operator = (const SimpleRefCount &o) + { + return *this; + } + /** + * Increment the reference count. This method should not be called + * by user code. SimpleRefCount instances are expected to be used in + * conjunction with the Ptr template which would make calling Ref + * unecessary and dangerous. + */ + inline void Ref (void) const + { + m_count++; + } + /** + * Decrement the reference count. This method should not be called + * by user code. SimpleRefCount instances are expected to be used in + * conjunction with the Ptr template which would make calling Ref + * unecessary and dangerous. + */ + inline void Unref (void) const + { + m_count--; + if (m_count == 0) + { + delete static_cast (const_cast (this)); + } + } + + /** + * Get the reference count of the object. + * Normally not needed; for language bindings. + */ + uint32_t GetReferenceCount (void) const + { + return m_count; + } + +private: + // Note we make this mutable so that the const methods can still + // change it. + mutable uint32_t m_count; +}; + +} // namespace ns3 + +#endif /* SIMPLE_REF_COUNT_H */ diff --git a/src/core/system-thread.h b/src/core/system-thread.h index 05b3108dc..c97285197 100644 --- a/src/core/system-thread.h +++ b/src/core/system-thread.h @@ -42,7 +42,7 @@ class SystemThreadImpl; * * Synchronization between threads is provided via the SystemMutex class. */ -class SystemThread +class SystemThread : public SimpleRefCount { public: /** @@ -115,22 +115,6 @@ public: */ ~SystemThread(); - /** - * Increment the reference count. This method should not be called - * by user code. Object instances are expected to be used in conjunction - * of the Ptr template which would make calling Ref unecessary and - * dangerous. - */ - inline void Ref (void) const; - - /** - * Decrement the reference count. This method should not be called - * by user code. Object instances are expected to be used in conjunction - * of the Ptr template which would make calling Ref unecessary and - * dangerous. - */ - inline void Unref (void) const; - /** * @brief Start a thread of execution, running the provided callback. */ @@ -181,26 +165,9 @@ public: private: SystemThreadImpl * m_impl; - mutable uint32_t m_count; bool m_break; }; - void -SystemThread::Ref (void) const -{ - m_count++; -} - - void -SystemThread::Unref (void) const -{ - m_count--; - if (m_count == 0) - { - delete this; - } -} - } //namespace ns3 #endif /* SYSTEM_THREAD_H */ diff --git a/src/core/trace-source-accessor.cc b/src/core/trace-source-accessor.cc index 841e88442..7ffe93415 100644 --- a/src/core/trace-source-accessor.cc +++ b/src/core/trace-source-accessor.cc @@ -22,23 +22,8 @@ namespace ns3 { TraceSourceAccessor::TraceSourceAccessor () - : m_count (1) {} TraceSourceAccessor::~TraceSourceAccessor () {} -void -TraceSourceAccessor::Ref (void) const -{ - m_count++; -} -void -TraceSourceAccessor::Unref (void) const -{ - m_count--; - if (m_count == 0) - { - delete this; - } -} } // namespace ns3 diff --git a/src/core/trace-source-accessor.h b/src/core/trace-source-accessor.h index e85f260ca..b86224e26 100644 --- a/src/core/trace-source-accessor.h +++ b/src/core/trace-source-accessor.h @@ -23,6 +23,7 @@ #include #include "callback.h" #include "ptr.h" +#include "simple-ref-count.h" namespace ns3 { @@ -36,13 +37,11 @@ class ObjectBase; * This class abstracts the kind of trace source to which we want to connect * and provides services to Connect and Disconnect a sink to a trace source. */ -class TraceSourceAccessor +class TraceSourceAccessor : public SimpleRefCount { public: TraceSourceAccessor (); virtual ~TraceSourceAccessor (); - void Ref (void) const; - void Unref (void) const; /** * \param obj the object instance which contains the target trace source. @@ -66,8 +65,6 @@ public: * \param cb the callback to disconnect from the target trace source. */ virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0; -private: - mutable uint32_t m_count; }; /** diff --git a/src/core/unix-system-thread.cc b/src/core/unix-system-thread.cc index 16eb5ff43..676d4d8e0 100644 --- a/src/core/unix-system-thread.cc +++ b/src/core/unix-system-thread.cc @@ -141,8 +141,7 @@ SystemThreadImpl::DoRun (void *arg) // class above. // SystemThread::SystemThread (Callback callback) - : m_impl (new SystemThreadImpl (callback)), - m_count (1) + : m_impl (new SystemThreadImpl (callback)) { NS_LOG_FUNCTION_NOARGS (); } diff --git a/src/core/wscript b/src/core/wscript index 40f146858..6144afd44 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -90,6 +90,7 @@ def build(bld): 'callback.h', 'object-base.h', 'ref-count-base.h', + 'simple-ref-count.h', 'type-id.h', 'attribute-list.h', 'ptr.h', diff --git a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h index 8d4c404e2..e7d35995f 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h +++ b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h @@ -31,7 +31,7 @@ namespace dot11s { * \ingroup dot11s * \brief Describes one unit of beacon timing element */ -class IeBeaconTimingUnit : public RefCountBase +class IeBeaconTimingUnit : public SimpleRefCount { public: IeBeaconTimingUnit (); diff --git a/src/devices/mesh/dot11s/ie-dot11s-preq.h b/src/devices/mesh/dot11s/ie-dot11s-preq.h index 8471f6673..74df22d46 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-preq.h +++ b/src/devices/mesh/dot11s/ie-dot11s-preq.h @@ -33,7 +33,7 @@ namespace dot11s { * \brief Describes an address unit in PREQ information element * See 7.3.2.96 for more details */ -class DestinationAddressUnit : public RefCountBase +class DestinationAddressUnit : public SimpleRefCount { public: DestinationAddressUnit (); diff --git a/src/devices/mesh/mesh-wifi-interface-mac-plugin.h b/src/devices/mesh/mesh-wifi-interface-mac-plugin.h index e064e482d..473be36ad 100644 --- a/src/devices/mesh/mesh-wifi-interface-mac-plugin.h +++ b/src/devices/mesh/mesh-wifi-interface-mac-plugin.h @@ -25,7 +25,7 @@ #include "ns3/packet.h" #include "ns3/mac48-address.h" #include "ns3/mesh-wifi-beacon.h" -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -38,7 +38,7 @@ class MeshWifiInterfaceMac; * * TODO: plugins description */ -class MeshWifiInterfaceMacPlugin : public RefCountBase +class MeshWifiInterfaceMacPlugin : public SimpleRefCount { public: /// This is for subclasses diff --git a/src/devices/mesh/wifi-information-element-vector.cc b/src/devices/mesh/wifi-information-element-vector.cc index 2e7b82b46..c779e3b58 100644 --- a/src/devices/mesh/wifi-information-element-vector.cc +++ b/src/devices/mesh/wifi-information-element-vector.cc @@ -36,6 +36,10 @@ #include "dot11s/ie-dot11s-rann.h" namespace ns3 { + +WifiInformationElement::~WifiInformationElement () +{} + bool operator< (WifiInformationElement const & a, WifiInformationElement const & b) { diff --git a/src/devices/mesh/wifi-information-element-vector.h b/src/devices/mesh/wifi-information-element-vector.h index e6506c58c..9e1725316 100644 --- a/src/devices/mesh/wifi-information-element-vector.h +++ b/src/devices/mesh/wifi-information-element-vector.h @@ -23,6 +23,7 @@ #define IE_VECTOR_H #include "ns3/header.h" +#include "ns3/simple-ref-count.h" namespace ns3 { class Packet; @@ -79,9 +80,10 @@ enum WifiElementId { * Element ID as defined in this standard. The Length field specifies the number of octets in the Information * field. */ -class WifiInformationElement : public RefCountBase +class WifiInformationElement : public SimpleRefCount { public: + virtual ~WifiInformationElement (); ///\name Each subclass must implement //\{ virtual void Print (std::ostream &os) const = 0; diff --git a/src/devices/wifi/interference-helper.h b/src/devices/wifi/interference-helper.h index 20caa6472..1409b5ceb 100644 --- a/src/devices/wifi/interference-helper.h +++ b/src/devices/wifi/interference-helper.h @@ -27,7 +27,7 @@ #include "wifi-preamble.h" #include "wifi-phy-standard.h" #include "ns3/nstime.h" -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -36,13 +36,13 @@ class ErrorRateModel; class InterferenceHelper { public: - class Event : public RefCountBase + class Event : public SimpleRefCount { public: Event (uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble, Time duration, double rxPower); - virtual ~Event (); + ~Event (); Time GetDuration (void) const; Time GetStartTime (void) const; diff --git a/src/node/ipv4-route.h b/src/node/ipv4-route.h index d58f9bb87..db89413e0 100644 --- a/src/node/ipv4-route.h +++ b/src/node/ipv4-route.h @@ -23,7 +23,7 @@ #include #include -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" #include "ipv4-address.h" namespace ns3 { @@ -38,7 +38,8 @@ class NetDevice; * This is a reference counted object. In the future, we will add other * entries from struct dst_entry, struct rtable, and struct dst_ops as needed. */ -class Ipv4Route : public RefCountBase { +class Ipv4Route : public SimpleRefCount +{ public: Ipv4Route (); @@ -103,7 +104,8 @@ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route); * * \brief Ipv4 multicast route cache entry (similar to Linux struct mfc_cache) */ -class Ipv4MulticastRoute : public RefCountBase { +class Ipv4MulticastRoute : public SimpleRefCount +{ public: Ipv4MulticastRoute (); diff --git a/src/node/ipv6-route.h b/src/node/ipv6-route.h index 0b7c37ec7..c7554f225 100644 --- a/src/node/ipv6-route.h +++ b/src/node/ipv6-route.h @@ -25,7 +25,7 @@ #include #include -#include "ns3/ref-count-base.h" +#include "ns3/simple-ref-count.h" #include "ipv6-address.h" @@ -39,7 +39,7 @@ class NetDevice; * \class Ipv6Route * \brief IPv6 route cache entry. */ -class Ipv6Route : public RefCountBase +class Ipv6Route : public SimpleRefCount { public: /** @@ -129,7 +129,7 @@ std::ostream& operator<< (std::ostream& os, Ipv6Route const& route); * \class Ipv6MulticastRoute * \brief IPv6 multicast route entry. */ -class Ipv6MulticastRoute : public RefCountBase +class Ipv6MulticastRoute : public SimpleRefCount { public: /** diff --git a/src/node/packetbb.cc b/src/node/packetbb.cc index 27292f253..67bde24cf 100644 --- a/src/node/packetbb.cc +++ b/src/node/packetbb.cc @@ -497,7 +497,6 @@ PbbAddressTlvBlock::operator!= (const PbbAddressTlvBlock &other) const PbbPacket::PbbPacket (void) { - m_refCount = 1; m_version = VERSION; m_hasseqnum = false; } @@ -746,21 +745,6 @@ PbbPacket::MessageClear (void) m_messageList.clear (); } -void -PbbPacket::Ref (void) const -{ - m_refCount++; -} - -void -PbbPacket::Unref (void) const -{ - m_refCount--; - if (m_refCount == 0) - { - delete this; - } -} TypeId PbbPacket::GetTypeId (void) @@ -947,7 +931,6 @@ PbbPacket::operator!= (const PbbPacket &other) const PbbMessage::PbbMessage () { - m_refCount = 1; /* Default to IPv4 */ m_addrSize = IPV4; m_hasOriginatorAddress = false; @@ -1274,22 +1257,6 @@ PbbMessage::AddressBlockClear (void) return m_addressBlockList.clear(); } -void -PbbMessage::Ref (void) const -{ - m_refCount++; -} - -void -PbbMessage::Unref (void) const -{ - m_refCount--; - if (m_refCount == 0) - { - delete this; - } -} - uint32_t PbbMessage::GetSerializedSize (void) const { @@ -1699,13 +1666,10 @@ PbbMessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const /* End PbbMessageIpv6 Class */ PbbAddressBlock::PbbAddressBlock () -{ - m_refCount = 1; -} +{} PbbAddressBlock::~PbbAddressBlock () -{ -} +{} /* Manipulating the address block */ @@ -2002,23 +1966,6 @@ PbbAddressBlock::TlvClear (void) { m_addressTlvList.Clear(); } - -void -PbbAddressBlock::Ref (void) const -{ - m_refCount++; -} - -void -PbbAddressBlock::Unref (void) const -{ - m_refCount--; - if (m_refCount == 0) - { - delete this; - } -} - uint32_t PbbAddressBlock::GetSerializedSize (void) const { @@ -2448,7 +2395,6 @@ PbbAddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter) PbbTlv::PbbTlv (void) { - m_refCount = 1; m_hasTypeExt = false; m_hasIndexStart = false; m_hasIndexStop = false; @@ -2573,22 +2519,6 @@ PbbTlv::HasValue (void) const return m_hasValue; } -void -PbbTlv::Ref (void) const -{ - m_refCount++; -} - -void -PbbTlv::Unref (void) const -{ - m_refCount--; - if (m_refCount == 0) - { - delete this; - } -} - uint32_t PbbTlv::GetSerializedSize (void) const { diff --git a/src/node/packetbb.h b/src/node/packetbb.h index 1ee3014dc..6d73df481 100644 --- a/src/node/packetbb.h +++ b/src/node/packetbb.h @@ -31,6 +31,7 @@ #include "ns3/address.h" #include "ns3/header.h" #include "ns3/buffer.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -360,7 +361,7 @@ private: * * See: http://tools.ietf.org/html/rfc5444 for details. */ -class PbbPacket : public Header +class PbbPacket : public SimpleRefCount { public: typedef std::list< Ptr >::iterator TlvIterator; @@ -595,10 +596,6 @@ public: */ void MessageClear (void); - /* Smart pointer methods */ - void Ref (void) const; - void Unref (void) const; - /* Methods implemented by all headers */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; @@ -644,8 +641,6 @@ private: bool m_hasseqnum; uint16_t m_seqnum; - - mutable uint32_t m_refCount; }; /** @@ -655,7 +650,7 @@ private: * virtual base class, when creating a message, you should instantiate either * PbbMessageIpv4 or PbbMessageIpv6. */ -class PbbMessage +class PbbMessage : public SimpleRefCount { public: typedef std::list< Ptr >::iterator TlvIterator; @@ -959,10 +954,6 @@ public: */ void AddressBlockClear (void); - /* Smart pointer methods */ - void Ref (void) const; - void Unref (void) const; - /** * \brief Deserializes a message, returning the correct object depending on * whether it is an IPv4 message or an IPv6 message. @@ -1048,8 +1039,6 @@ private: bool m_hasSequenceNumber; uint16_t m_sequenceNumber; - - mutable uint32_t m_refCount; }; /** @@ -1098,7 +1087,7 @@ protected: * This is a pure virtual base class, when creating address blocks, you should * instantiate either PbbAddressBlockIpv4 or PbbAddressBlockIpv6. */ -class PbbAddressBlock +class PbbAddressBlock : public SimpleRefCount { public: typedef std::list< Address >::iterator AddressIterator; @@ -1412,10 +1401,6 @@ public: */ void TlvClear (void); - /* Smart pointer methods */ - void Ref (void) const; - void Unref (void) const; - /** * \return The size (in bytes) needed to serialize this address block. */ @@ -1475,8 +1460,6 @@ private: std::list
m_addressList; std::list m_prefixList; PbbAddressTlvBlock m_addressTlvList; - - mutable uint32_t m_refCount; }; /** @@ -1520,11 +1503,11 @@ protected: /** * \brief A packet or message TLV */ -class PbbTlv +class PbbTlv : public SimpleRefCount { public: PbbTlv (void); - ~PbbTlv (void); + virtual ~PbbTlv (void); /** * \brief Sets the type of this TLV. @@ -1599,10 +1582,6 @@ public: */ bool HasValue (void) const; - /* Smart pointer methods */ - void Ref (void) const; - void Unref (void) const; - /** * \return The size (in bytes) needed to serialize this TLV. */ @@ -1672,8 +1651,6 @@ private: bool m_isMultivalue; bool m_hasValue; Buffer m_value; - - mutable uint32_t m_refCount; }; /** diff --git a/src/simulator/event-impl.cc b/src/simulator/event-impl.cc index 03db87d6c..42c6deb02 100644 --- a/src/simulator/event-impl.cc +++ b/src/simulator/event-impl.cc @@ -20,15 +20,13 @@ #include "event-impl.h" - namespace ns3 { EventImpl::~EventImpl () {} EventImpl::EventImpl () - : m_cancel (false), - m_count (1) + : m_cancel (false) {} void diff --git a/src/simulator/event-impl.h b/src/simulator/event-impl.h index 479eefc12..0bdb4a007 100644 --- a/src/simulator/event-impl.h +++ b/src/simulator/event-impl.h @@ -21,6 +21,7 @@ #define EVENT_IMPL_H #include +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -35,12 +36,10 @@ namespace ns3 { * most subclasses are usually created by one of the many Simulator::Schedule * methods. */ -class EventImpl +class EventImpl : public SimpleRefCount { public: EventImpl (); - inline void Ref (void) const; - inline void Unref (void) const; virtual ~EventImpl () = 0; /** * Called by the simulation engine to notify the event that it has expired. @@ -64,30 +63,8 @@ protected: private: bool m_cancel; - mutable uint32_t m_count; }; -}; // namespace ns3 - -namespace ns3 { - -void -EventImpl::Ref (void) const -{ - m_count++; -} - -void -EventImpl::Unref (void) const -{ - uint32_t c; - c = --m_count; - if (c == 0) - { - delete this; - } -} - } // namespace ns3 #endif /* EVENT_IMPL_H */