ensure singleton::get thread safe construct instance (#658)
* ensure singleton::get thread safe construct instance * fix singleton return reference Co-authored-by: xuweiqi <xuweiqi117@gmail.com>
This commit is contained in:
parent
012c62c748
commit
168ea8b0e1
@ -42,10 +42,6 @@ namespace library {
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static std::unique_ptr<Singleton> instance;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
Singleton::Singleton() {
|
Singleton::Singleton() {
|
||||||
|
|
||||||
manifest.initialize();
|
manifest.initialize();
|
||||||
@ -54,10 +50,8 @@ Singleton::Singleton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Singleton const & Singleton::get() {
|
Singleton const & Singleton::get() {
|
||||||
if (!instance.get()) {
|
static Singleton instance;
|
||||||
instance.reset(new Singleton);
|
return instance;
|
||||||
}
|
|
||||||
return *instance.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user