From 81291381f876e7a2c01889ddc3d849d88520af41 Mon Sep 17 00:00:00 2001
From: Richard Linden <none@none>
Date: Fri, 26 Apr 2013 11:21:16 -0700
Subject: [PATCH] SH-4080 WIP interesting: random crash on Mac fixed Mac crash
 related to non-reentrant singleton constructor

---
 indra/llcommon/llsingleton.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h
index 1cbefb1cd05..165344ed194 100644
--- a/indra/llcommon/llsingleton.h
+++ b/indra/llcommon/llsingleton.h
@@ -83,8 +83,10 @@ class LLSingleton : private boost::noncopyable
 
 		void construct()
 		{
+			sReentrantConstructorGuard = true;
 			mSingletonInstance = new DERIVED_TYPE(); 
 			mInitState = INITIALIZING;
+			sReentrantConstructorGuard = false;
 		}
 
 		~SingletonInstanceData()
@@ -174,7 +176,7 @@ class LLSingleton : private boost::noncopyable
 	// Use this to avoid accessing singletons before the can safely be constructed
 	static bool instanceExists()
 	{
-		return getSingletonData().mInitState == INITIALIZED;
+		return sReentrantConstructorGuard || getSingletonData().mInitState == INITIALIZED;
 	}
 	
 	// Has this singleton already been deleted?
@@ -194,6 +196,11 @@ class LLSingleton : private boost::noncopyable
 	}
 
 	virtual void initSingleton() {}
+
+	static bool sReentrantConstructorGuard;
 };
 
+template<typename T>
+bool LLSingleton<T>::sReentrantConstructorGuard = false;
+
 #endif
-- 
GitLab