DRTVWR-494: LLParamSingleton::initParamSingleton() returns reference.

master
Nat Goodspeed 2019-12-12 17:23:54 -05:00
parent 7e9c5dd0a3
commit 0a9a20a5df
1 changed files with 16 additions and 13 deletions

View File

@ -654,20 +654,10 @@ private:
typedef LLSingleton<DERIVED_TYPE> super;
using typename super::LockStatic;
public:
using super::deleteSingleton;
using super::instanceExists;
using super::wasDeleted;
// 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.
// states, returning a pointer to the new instance.
template <typename... Args>
static DERIVED_TYPE* initParamSingleton(Args&&... args)
static DERIVED_TYPE* initParamSingleton_(Args&&... args)
{
// In case racing threads both call initParamSingleton() at the same
// time, serialize them. One should initialize; the other should see
@ -709,7 +699,7 @@ public:
[&](){
super::loginfos(super::template classname<DERIVED_TYPE>().c_str(),
"::initParamSingleton() on main thread");
return initParamSingleton(std::forward<Args>(args)...);
return initParamSingleton_(std::forward<Args>(args)...);
});
super::loginfos(super::template classname<DERIVED_TYPE>().c_str(),
"::initParamSingleton() returning on requesting thread");
@ -717,6 +707,19 @@ public:
}
}
public:
using super::deleteSingleton;
using super::instanceExists;
using super::wasDeleted;
/// initParamSingleton() constructs the instance, returning a reference.
/// Pass whatever arguments are required to construct DERIVED_TYPE.
template <typename... Args>
static DERIVED_TYPE& initParamSingleton(Args&&... args)
{
return *initParamSingleton_(std::forward<Args>(args)...);
}
static DERIVED_TYPE* getInstance()
{
// In case racing threads call getInstance() at the same moment as