summaryrefslogtreecommitdiff
path: root/indra/llcommon/llsingleton.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2015-06-26 13:03:59 -0400
committerNat Goodspeed <nat@lindenlab.com>2015-06-26 13:03:59 -0400
commit687efd84eabc524e339e61458b0cbf53f9a38f8a (patch)
tree492879aa9fa5e9383a5a3a7c285e7aaf4cc6df13 /indra/llcommon/llsingleton.cpp
parentaefdba1230de456784d220982ab8b4dbe3cde17d (diff)
MAINT-5232: Loosen LLSingleton circularity constraints slightly.
LLSingleton explicitly supports circular dependencies: initialization performed during an LLSingleton subclass's initSingleton() method may recursively call that same subclass's getInstance() method. On the other hand, circularity from a subclass constructor cannot be permitted, else getInstance() would have to return a partially-constructed object. Our dependency tracking circularity check initially forbade both. Loosen it to permit references from within initSingleton().
Diffstat (limited to 'indra/llcommon/llsingleton.cpp')
-rwxr-xr-xindra/llcommon/llsingleton.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/indra/llcommon/llsingleton.cpp b/indra/llcommon/llsingleton.cpp
index a3edf925ad..2813814ae1 100755
--- a/indra/llcommon/llsingleton.cpp
+++ b/indra/llcommon/llsingleton.cpp
@@ -123,7 +123,7 @@ void LLSingletonBase::pop_initializing()
list.pop_back();
}
-void LLSingletonBase::capture_dependency()
+void LLSingletonBase::capture_dependency(EInitState initState)
{
// Did this getInstance() call come from another LLSingleton, or from
// vanilla application code? Note that although this is a nontrivial
@@ -150,11 +150,18 @@ void LLSingletonBase::capture_dependency()
// is the actual LLSingletonBase instance.
out << typeid(**found).name() << " -> ";
}
- // DEBUGGING: Initially, make this crump. We want to know how bad
- // the problem is before we add it to the long, sad list of
- // ominous warnings that everyone always ignores.
- logerrs("LLSingleton circularity: ", out.str().c_str(),
- typeid(*this).name());
+ // We promise to capture dependencies from both the constructor
+ // and the initSingleton() method, so an LLSingleton's instance
+ // pointer is on the initializing list during both. Now that we've
+ // detected circularity, though, we must distinguish the two. If
+ // the recursive call is from the constructor, we CAN'T honor it:
+ // otherwise we'd be returning a pointer to a partially-
+ // constructed object! But from initSingleton() is okay: that
+ // method exists specifically to support circularity.
+ // Decide which log helper to call based on initState. They have
+ // identical signatures.
+ ((initState == CONSTRUCTING)? logerrs : logwarns)
+ ("LLSingleton circularity: ", out.str().c_str(), typeid(*this).name(), "");
}
else
{