From b9a9b0017dd4714cbca4b0ddb69ed5e6b2f09528 Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Wed, 9 Mar 2011 17:01:08 -0800 Subject: Fix for "doubleton" error using LLInstanceTracker across shared library boundaries. --- indra/llcommon/llinstancetracker.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'indra/llcommon/llinstancetracker.h') diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h index 4945461d62..b971b2f914 100644 --- a/indra/llcommon/llinstancetracker.h +++ b/indra/llcommon/llinstancetracker.h @@ -37,14 +37,21 @@ #include #include +class LL_COMMON_API LLInstanceTrackerBase : public boost::noncopyable +{ + protected: + static void * & getInstances(std::type_info const & info); +}; + /// This mix-in class adds support for tracking all instances of the specified class parameter T /// The (optional) key associates a value of type KEY with a given instance of T, for quick lookup /// If KEY is not provided, then instances are stored in a simple set /// @NOTE: see explicit specialization below for default KEY==T* case template -class LLInstanceTracker : boost::noncopyable +class LLInstanceTracker : public LLInstanceTrackerBase { typedef typename std::map InstanceMap; + typedef LLInstanceTracker MyT; typedef boost::function KeyGetter; typedef boost::function InstancePtrGetter; public: @@ -99,25 +106,26 @@ private: static InstanceMap& getMap_() { - if (! sInstances) + void * & instances = getInstances(typeid(MyT)); + if (! instances) { - sInstances = new InstanceMap; + instances = new InstanceMap; } - return *sInstances; + return * static_cast(instances); } private: KEY mKey; - static InstanceMap* sInstances; }; /// explicit specialization for default case where KEY is T* /// use a simple std::set template -class LLInstanceTracker +class LLInstanceTracker : public LLInstanceTrackerBase { typedef typename std::set InstanceSet; + typedef LLInstanceTracker MyT; public: /// Dereferencing key_iter gives you a T* (since T* is the key) typedef typename InstanceSet::iterator key_iter; @@ -172,19 +180,17 @@ protected: static InstanceSet& getSet_() { - if (! sInstances) + void * & instances = getInstances(typeid(MyT)); + if (! instances) { - sInstances = new InstanceSet; + instances = new InstanceSet; } - return *sInstances; + return * static_cast(instances); } - static InstanceSet* sInstances; static S32 sIterationNestDepth; }; -template typename LLInstanceTracker::InstanceMap* LLInstanceTracker::sInstances = NULL; -template typename LLInstanceTracker::InstanceSet* LLInstanceTracker::sInstances = NULL; template S32 LLInstanceTracker::sIterationNestDepth = 0; #endif -- cgit v1.2.3