blob: e6bd99d450117ffe7a3dc312378c4bfdc666147d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "StarRootBase.hpp"
namespace Star {
atomic<RootBase*> RootBase::s_singleton;
RootBase* RootBase::singletonPtr() {
return s_singleton.load();
}
RootBase& RootBase::singleton() {
auto ptr = s_singleton.load();
if (!ptr)
throw RootException("RootBase::singleton() called with no Root instance available");
else
return *ptr;
}
RootBase::RootBase() {
RootBase* oldRoot = nullptr;
if (!s_singleton.compare_exchange_strong(oldRoot, this))
throw RootException("Singleton Root has been constructed twice");
}
}
|