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:
seventh 2022-11-09 10:44:32 +08:00 committed by GitHub
parent 012c62c748
commit 168ea8b0e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,10 +42,6 @@ namespace library {
/////////////////////////////////////////////////////////////////////////////////////////////////
static std::unique_ptr<Singleton> instance;
/////////////////////////////////////////////////////////////////////////////////////////////////
Singleton::Singleton() {
manifest.initialize();
@ -54,10 +50,8 @@ Singleton::Singleton() {
}
Singleton const & Singleton::get() {
if (!instance.get()) {
instance.reset(new Singleton);
}
return *instance.get();
static Singleton instance;
return instance;
}
/////////////////////////////////////////////////////////////////////////////////////////////////