45#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_SINGLETON_INL
46#define LASS_GUARDIAN_OF_INCLUSION_UTIL_SINGLETON_INL
59template <
class T,
int DP>
60Singleton<T, DP>::Singleton():
61 impl::SingletonBase(),
62 instance_(new TInstance)
68template <
class T,
int DP>
69Singleton<T, DP>::~Singleton()
81template <
class T,
int DP>
84 static std::atomic<TSelf*> neo{
nullptr };
85 static std::atomic<int> semaphore{ 1 };
87 if (deadReference(
false))
89 std::cerr <<
"[LASS RUN MSG] Dead reference detected at '" << neo.load(std::memory_order_relaxed)
90 <<
"' of singleton '" <<
typeid(TInstance).name() <<
"' with destruction priority '"
91 << destructionPriority <<
"'" << std::endl;
95 TSelf* one = neo.load(std::memory_order_acquire);
98 LASS_LOCK_INTEGRAL(semaphore)
100 one = neo.load(std::memory_order_relaxed);
105 neo.store(one, std::memory_order_release);
110#if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
111# pragma warning(suppress: 6011)
113 return one->instance_.get();
122template <
class T,
int DP>
123bool Singleton<T, DP>::deadReference(
bool setReferenceToDead)
125 static std::atomic<int> dead{
false };
126 if (setReferenceToDead)
128 dead.store(
true, std::memory_order_release);
133 return dead.load(std::memory_order_acquire);
static TInstance * instance()
Return pointer to singleton instance.
void subscribeInstance(int iDestructionPriority)
Subscribe to the singleton guard.
general utility, debug facilities, ...
Library for Assembled Shared Sources.