Skip to content
Snippets Groups Projects
Commit 860a8286 authored by brad kittenbrink's avatar brad kittenbrink
Browse files

Attemt at fixing "doubleton" problems across shared lib boundaries. ...

Attemt at fixing "doubleton" problems across shared lib boundaries.  Singletons now keep their SingletonInstaceData in a big global map in the llcommon module.
parent dc62495d
No related branches found
No related tags found
No related merge requests found
...@@ -74,6 +74,7 @@ set(llcommon_SOURCE_FILES ...@@ -74,6 +74,7 @@ set(llcommon_SOURCE_FILES
llsdserialize_xml.cpp llsdserialize_xml.cpp
llsdutil.cpp llsdutil.cpp
llsecondlifeurls.cpp llsecondlifeurls.cpp
llsingleton.cpp
llstat.cpp llstat.cpp
llstacktrace.cpp llstacktrace.cpp
llstreamtools.cpp llstreamtools.cpp
......
/**
* @file llsingleton.cpp
* @author Brad Kittenbrink
*
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 2009-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llsingleton.h"
std::map<std::string, void *> LLSingletonRegistry::sSingletonMap;
...@@ -33,7 +33,30 @@ ...@@ -33,7 +33,30 @@
#include "llerror.h" // *TODO: eliminate this #include "llerror.h" // *TODO: eliminate this
#include <typeinfo>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/any.hpp>
/// @brief A global registry of all singletons to prevent duplicate allocations
/// across shared library boundaries
class LL_COMMON_API LLSingletonRegistry {
private:
typedef std::map<std::string, void *> TypeMap;
static TypeMap sSingletonMap;
public:
template<typename T> static void * & get()
{
std::string name(typeid(T).name());
if(0 == sSingletonMap.count(name))
{
sSingletonMap[name] = NULL;
}
return sSingletonMap[typeid(T).name()];
}
};
// LLSingleton implements the getInstance() method part of the Singleton // LLSingleton implements the getInstance() method part of the Singleton
// pattern. It can't make the derived class constructors protected, though, so // pattern. It can't make the derived class constructors protected, though, so
...@@ -107,8 +130,16 @@ class LLSingleton : private boost::noncopyable ...@@ -107,8 +130,16 @@ class LLSingleton : private boost::noncopyable
static SingletonInstanceData& getData() static SingletonInstanceData& getData()
{ {
void * & registry = LLSingletonRegistry::get<DERIVED_TYPE>();
static SingletonInstanceData data; static SingletonInstanceData data;
return data;
// *TODO - look into making this threadsafe
if(NULL == registry)
{
registry = &data;
}
return *static_cast<SingletonInstanceData *>(registry);
} }
static DERIVED_TYPE* getInstance() static DERIVED_TYPE* getInstance()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment