Skip to content
Snippets Groups Projects
Commit 68505edf authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

DRTVWR-494: LLParamSingleton<T>::initParamSingleton() now returns T*.

So does LLLockedSingleton<T>::construct().
parent a6f5e55d
No related branches found
No related tags found
No related merge requests found
...@@ -650,9 +650,15 @@ class LLParamSingleton : public LLSingleton<DERIVED_TYPE> ...@@ -650,9 +650,15 @@ class LLParamSingleton : public LLSingleton<DERIVED_TYPE>
using super::instanceExists; using super::instanceExists;
using super::wasDeleted; using super::wasDeleted;
// Passes arguments to DERIVED_TYPE's constructor and sets appropriate states // Passes arguments to DERIVED_TYPE's constructor and sets appropriate
// states. We'd rather return a reference than a pointer, but the test for
// redundant calls makes that awkward. The compiler, unaware that
// logerrs() won't return, requires that that alternative return
// *something*. But what? It can't be a dummy static instance because
// there should be only one instance of any LLSingleton subclass! Easier
// to allow that case to return nullptr.
template <typename... Args> template <typename... Args>
static void initParamSingleton(Args&&... args) static DERIVED_TYPE* initParamSingleton(Args&&... args)
{ {
// In case racing threads both call initParamSingleton() at the same // In case racing threads both call initParamSingleton() at the same
// time, serialize them. One should initialize; the other should see // time, serialize them. One should initialize; the other should see
...@@ -664,10 +670,12 @@ class LLParamSingleton : public LLSingleton<DERIVED_TYPE> ...@@ -664,10 +670,12 @@ class LLParamSingleton : public LLSingleton<DERIVED_TYPE>
super::logerrs("Tried to initialize singleton ", super::logerrs("Tried to initialize singleton ",
super::template classname<DERIVED_TYPE>().c_str(), super::template classname<DERIVED_TYPE>().c_str(),
" twice!"); " twice!");
return nullptr;
} }
else else
{ {
super::constructSingleton(lk, std::forward<Args>(args)...); super::constructSingleton(lk, std::forward<Args>(args)...);
return lk->mInstance;
} }
} }
...@@ -740,9 +748,9 @@ class LLLockedSingleton : public LLParamSingleton<DT> ...@@ -740,9 +748,9 @@ class LLLockedSingleton : public LLParamSingleton<DT>
using super::instanceExists; using super::instanceExists;
using super::wasDeleted; using super::wasDeleted;
static void construct() static DT* construct()
{ {
super::initParamSingleton(); return super::initParamSingleton();
} }
}; };
......
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