Skip to content
Snippets Groups Projects
Commit 84af0e98 authored by Richard Linden's avatar Richard Linden
Browse files

SH-4080 WIP interesting: random crash on Mac

potential fix for crasher
cleaned up llsingleton
parent c6737163
No related branches found
No related tags found
No related merge requests found
...@@ -28,5 +28,4 @@ ...@@ -28,5 +28,4 @@
#include "llsingleton.h" #include "llsingleton.h"
std::map<std::string, void *> * LLSingletonRegistry::sSingletonMap = NULL;
...@@ -30,38 +30,6 @@ ...@@ -30,38 +30,6 @@
#include <typeinfo> #include <typeinfo>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.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;
static void checkInit()
{
if(sSingletonMap == NULL)
{
sSingletonMap = new TypeMap();
}
}
public:
template<typename T> static void * & get()
{
std::string name(typeid(T).name());
checkInit();
// the first entry of the pair returned by insert will be either the existing
// iterator matching our key, or the newly inserted NULL initialized entry
// see "Insert element" in http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html
TypeMap::iterator result =
sSingletonMap->insert(std::make_pair(name, (void*)NULL)).first;
return result->second;
}
};
// 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
// you have to do that yourself. // you have to do that yourself.
...@@ -90,10 +58,9 @@ template <typename DERIVED_TYPE> ...@@ -90,10 +58,9 @@ template <typename DERIVED_TYPE>
class LLSingleton : private boost::noncopyable class LLSingleton : private boost::noncopyable
{ {
protected: private:
typedef enum e_init_state typedef enum e_init_state
{ {
UNINITIALIZED,
CONSTRUCTING, CONSTRUCTING,
INITIALIZING, INITIALIZING,
INITIALIZED, INITIALIZED,
...@@ -109,8 +76,11 @@ protected: ...@@ -109,8 +76,11 @@ protected:
SingletonInstanceData() SingletonInstanceData()
: mSingletonInstance(NULL), : mSingletonInstance(NULL),
mInitState(UNINITIALIZED) mInitState(CONSTRUCTING)
{} {
mSingletonInstance = new DERIVED_TYPE();
mInitState = INITIALIZING;
}
~SingletonInstanceData() ~SingletonInstanceData()
{ {
...@@ -151,12 +121,12 @@ public: ...@@ -151,12 +121,12 @@ public:
*/ */
static void deleteSingleton() static void deleteSingleton()
{ {
SingletonInstanceData& data = getSingletonData(); delete getSingletonData().mSingletonInstance;
delete data.mSingletonInstance; getSingletonData().mSingletonInstance = NULL;
data.mSingletonInstance = NULL; getSingletonData().mInitState = DELETED;
data.mInitState = DELETED;
} }
static DERIVED_TYPE* getInstance() static DERIVED_TYPE* getInstance()
{ {
SingletonInstanceData& data = getSingletonData(); SingletonInstanceData& data = getSingletonData();
...@@ -171,13 +141,11 @@ public: ...@@ -171,13 +141,11 @@ public:
llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl; llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl;
} }
if (!data.mSingletonInstance) if (data.mInitState == INITIALIZING)
{ {
data.mInitState = CONSTRUCTING; // go ahead and flag ourselves as initialized so we can be reentrant during initialization
data.mSingletonInstance = new DERIVED_TYPE();
data.mInitState = INITIALIZING;
data.mSingletonInstance->initSingleton();
data.mInitState = INITIALIZED; data.mInitState = INITIALIZED;
data.mSingletonInstance->initSingleton();
} }
return data.mSingletonInstance; return data.mSingletonInstance;
...@@ -185,7 +153,7 @@ public: ...@@ -185,7 +153,7 @@ public:
static DERIVED_TYPE* getIfExists() static DERIVED_TYPE* getIfExists()
{ {
SingletonInstanceData& data = getSingletonData(); SingletonInstanceData& data = getData();
return data.mSingletonInstance; return data.mSingletonInstance;
} }
...@@ -211,20 +179,14 @@ public: ...@@ -211,20 +179,14 @@ public:
} }
private: private:
static SingletonInstanceData& getSingletonData() static SingletonInstanceData& getSingletonData()
{ {
// this is static to cache the lookup results // this is static to cache the lookup results
static void * & registry = LLSingletonRegistry::get<DERIVED_TYPE>(); static SingletonInstanceData sData;
return sData;
// *TODO - look into making this threadsafe
if(NULL == registry)
{
static SingletonInstanceData data;
registry = &data;
}
return *static_cast<SingletonInstanceData *>(registry);
} }
virtual void initSingleton() {} virtual void initSingleton() {}
}; };
......
...@@ -362,6 +362,10 @@ PeriodicRecording::PeriodicRecording( U32 num_periods, EPlayState state) ...@@ -362,6 +362,10 @@ PeriodicRecording::PeriodicRecording( U32 num_periods, EPlayState state)
: mAutoResize(num_periods == 0), : mAutoResize(num_periods == 0),
mCurPeriod(0) mCurPeriod(0)
{ {
if (mAutoResize)
{
num_periods = 1;
}
if (num_periods) if (num_periods)
{ {
mRecordingPeriods.resize(num_periods); mRecordingPeriods.resize(num_periods);
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
class LLObjectSelection; class LLObjectSelection;
class LLToolSelect : public LLTool, public LLSingleton<LLToolSelect> class LLToolSelect : public LLTool
{ {
public: public:
LLToolSelect( LLToolComposite* composite ); LLToolSelect( LLToolComposite* composite );
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "llui.h" #include "llui.h"
#include <list> #include <list>
#include <set> #include <set>
#include "lluiimage.h"
const U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128; const U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128;
......
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