From 579a173fbf72fc21fdac9ca25b5d1a0d2cdf405c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 11:21:42 +0200 Subject: [PATCH] avoid problems with recursive use of Object::DoCollectSources --- src/core/object.cc | 28 +++++++++++++++++++++------- src/core/object.h | 1 + src/core/trace-resolver.cc | 18 ------------------ src/core/trace-resolver.h | 4 ---- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/core/object.cc b/src/core/object.cc index c2d7c389a..565897947 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -23,8 +23,11 @@ #include "singleton.h" #include "uid-manager.h" #include "trace-resolver.h" +#include "debug.h" #include +NS_DEBUG_COMPONENT_DEFINE ("Object"); + namespace { class IidManager : public ns3::UidManager @@ -173,6 +176,7 @@ Object::Object () : m_count (1), m_iid (Object::iid), m_disposed (false), + m_collecting (false), m_next (this) {} Object::~Object () @@ -296,15 +300,23 @@ void Object::DoCollectSources (std::string path, const TraceContext &context, TraceResolver::SourceCollection *collection) { - Object *current = this->m_next; - if (collection->IsFlagSet ()) - { - return; - } - collection->SetFlag (); + Object *current; + current = this; + do { + if (current->m_collecting) + { + return; + } + current = current->m_next; + } while (current != this); + + m_collecting = true; + + current = this->m_next; while (current != this) { NS_ASSERT (current != 0); + NS_DEBUG ("collect current=" << current); InterfaceId cur = current->m_iid; while (cur != Object::iid) { @@ -312,12 +324,14 @@ Object::DoCollectSources (std::string path, const TraceContext &context, std::string fullpath = path; fullpath.append ("/$"); fullpath.append (name); + NS_DEBUG ("collect: " << fullpath); current->GetTraceResolver ()->CollectSources (fullpath, context, collection); cur = InterfaceId::LookupParent (cur); } current = current->m_next; } - collection->ClearFlag (); + + m_collecting = false; } } // namespace ns3 diff --git a/src/core/object.h b/src/core/object.h index 32f1806a4..8661d7f8a 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -170,6 +170,7 @@ private: mutable uint32_t m_count; InterfaceId m_iid; bool m_disposed; + bool m_collecting; Object *m_next; }; diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index a5f5267a4..d0191f859 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -108,22 +108,4 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const } } -void -TraceResolver::SourceCollection::SetFlag (void) -{ - m_flag = true; -} - -void -TraceResolver::SourceCollection::ClearFlag (void) -{ - m_flag = false; -} -bool -TraceResolver::SourceCollection::IsFlagSet (void) -{ - return m_flag; -} - - }//namespace ns3 diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index 639ddcb85..c3802619a 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -76,9 +76,6 @@ public: void Print (std::ostream &os) const; void AddUnique (std::string path, const TraceContext &context, std::string help); - void SetFlag (void); - void ClearFlag (void); - bool IsFlagSet (void); private: struct Source { @@ -88,7 +85,6 @@ public: }; typedef std::vector SourceVector; SourceVector m_sources; - bool m_flag; }; virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0;