summaryrefslogtreecommitdiff
path: root/indra/llcommon/llsingleton.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llsingleton.h')
-rw-r--r--indra/llcommon/llsingleton.h55
1 files changed, 26 insertions, 29 deletions
diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h
index 64027c16c7..b5659e053c 100644
--- a/indra/llcommon/llsingleton.h
+++ b/indra/llcommon/llsingleton.h
@@ -1,24 +1,24 @@
-/**
+/**
* @file llsingleton.h
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -35,6 +35,13 @@
#include "lockstatic.h"
#include "llthread.h" // on_main_thread()
#include "llmainthreadtask.h"
+#include "llprofiler.h"
+#include "llerror.h"
+
+#ifdef LL_WINDOWS
+#pragma warning(push)
+#pragma warning(disable : 4506) // no definition for inline function
+#endif
class LLSingletonBase: private boost::noncopyable
{
@@ -293,7 +300,7 @@ private:
// Use a recursive_mutex in case of constructor circularity. With a
// non-recursive mutex, that would result in deadlock.
typedef std::recursive_mutex mutex_t;
- mutex_t mMutex; // LockStatic looks for mMutex
+ LL_PROFILE_MUTEX_NAMED(mutex_t, mMutex, "Singleton Data"); // LockStatic looks for mMutex
EInitState mInitState{UNINITIALIZED};
DERIVED_TYPE* mInstance{nullptr};
@@ -415,7 +422,7 @@ protected:
// deleteSingleton() to defend against manual deletion. When we moved
// cleanup to deleteSingleton(), we hit crashes due to dangling
// pointers in the MasterList.
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
lk->mInstance = nullptr;
lk->mInitState = DELETED;
@@ -443,7 +450,7 @@ public:
// Hold the lock while we call cleanupSingleton() and the destructor.
// Our destructor also instantiates LockStatic, requiring a recursive
// mutex.
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
// of course, only cleanup and delete if there's something there
if (lk->mInstance)
{
@@ -500,7 +507,7 @@ public:
{ // nested scope for 'lk'
// In case racing threads call getInstance() at the same moment,
// serialize the calls.
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
switch (lk->mInitState)
{
@@ -528,6 +535,7 @@ public:
classname<DERIVED_TYPE>(),
" -- creating new instance"});
// fall through
+ [[fallthrough]];
case UNINITIALIZED:
case QUEUED:
// QUEUED means some secondary thread has already requested an
@@ -589,7 +597,7 @@ public:
static bool instanceExists()
{
// defend any access to sData from racing threads
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
return lk->mInitState == INITIALIZED;
}
@@ -599,7 +607,7 @@ public:
static bool wasDeleted()
{
// defend any access to sData from racing threads
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
return lk->mInitState == DELETED;
}
};
@@ -638,7 +646,7 @@ private:
// In case racing threads both call initParamSingleton() at the same
// time, serialize them. One should initialize; the other should see
// mInitState already set.
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
// For organizational purposes this function shouldn't be called twice
if (lk->mInitState != super::UNINITIALIZED)
{
@@ -702,7 +710,7 @@ public:
{
// In case racing threads call getInstance() at the same moment as
// initParamSingleton(), serialize the calls.
- LockStatic lk;
+ LockStatic lk; LL_PROFILE_MUTEX_LOCK(lk->mMutex);
switch (lk->mInitState)
{
@@ -807,17 +815,6 @@ private: \
DERIVED_CLASS(__VA_ARGS__)
/**
- * A slight variance from the above, but includes the "override" keyword
- */
-#define LLSINGLETON_C11(DERIVED_CLASS) \
-private: \
- /* implement LLSingleton pure virtual method whose sole purpose */ \
- /* is to remind people to use this macro */ \
- virtual void you_must_use_LLSINGLETON_macro() override {} \
- friend class LLSingleton<DERIVED_CLASS>; \
- DERIVED_CLASS()
-
-/**
* Use LLSINGLETON_EMPTY_CTOR(Foo); at the start of an LLSingleton<Foo>
* subclass body when the constructor is trivial:
*
@@ -835,13 +832,9 @@ private: \
/* LLSINGLETON() is carefully implemented to permit exactly this */ \
LLSINGLETON(DERIVED_CLASS) {}
-#define LLSINGLETON_EMPTY_CTOR_C11(DERIVED_CLASS) \
- /* LLSINGLETON() is carefully implemented to permit exactly this */ \
- LLSINGLETON_C11(DERIVED_CLASS) {}
-
// Relatively unsafe singleton implementation that is much faster
// and simpler than LLSingleton, but has no dependency tracking
-// or inherent thread safety and requires manual invocation of
+// or inherent thread safety and requires manual invocation of
// createInstance before first use.
template<class T>
class LLSimpleton
@@ -871,4 +864,8 @@ private:
template <class T>
T* LLSimpleton<T>::sInstance{ nullptr };
+#ifdef LL_WINDOWS
+#pragma warning(pop)
+#endif
+
#endif