diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2019-12-12 17:23:54 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2020-03-25 15:28:17 -0400 |
commit | 0a9a20a5df5ea7fd8f542e6f865a795a07ce5160 (patch) | |
tree | f7a93fe2d13e09b775ed9cf4a37475df7d01b605 | |
parent | 7e9c5dd0a3e583a9bec4e99d99b2efca358c6612 (diff) |
DRTVWR-494: LLParamSingleton::initParamSingleton() returns reference.
-rw-r--r-- | indra/llcommon/llsingleton.h | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h index 314ee2caa8..0c11e54910 100644 --- a/indra/llcommon/llsingleton.h +++ b/indra/llcommon/llsingleton.h @@ -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 |