Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/base/StarRootBase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/base/StarRootBase.cpp')
-rw-r--r--source/base/StarRootBase.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/source/base/StarRootBase.cpp b/source/base/StarRootBase.cpp
new file mode 100644
index 0000000..e6bd99d
--- /dev/null
+++ b/source/base/StarRootBase.cpp
@@ -0,0 +1,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");
+ }
+} \ No newline at end of file