[deploy] update singleton & FUCK msvc

This commit is contained in:
Nomango 2020-09-30 19:03:39 +08:00
parent 321ea81c89
commit f9348b8551
1 changed files with 4 additions and 26 deletions

View File

@ -19,8 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <memory>
#include <mutex>
namespace kiwano namespace kiwano
{ {
@ -31,22 +29,14 @@ class Singleton
public: public:
using object_type = _Ty; using object_type = _Ty;
static std::unique_ptr<object_type> instance_ptr_;
static inline object_type& GetInstance() static inline object_type& GetInstance()
{ {
return *GetInstancePtr(); return instance_;
} }
static inline object_type* GetInstancePtr() static inline object_type* GetInstancePtr()
{ {
std::call_once(once_, Singleton::Init); return &instance_;
return instance_ptr_.get();
}
static inline void DestroyInstance()
{
instance_ptr_.reset();
} }
protected: protected:
@ -54,22 +44,10 @@ protected:
Singleton(const Singleton&) = delete; Singleton(const Singleton&) = delete;
Singleton& operator=(const Singleton&) = delete; Singleton& operator=(const Singleton&) = delete;
private: static _Ty instance_;
static inline void Init()
{
if (!instance_ptr_)
{
instance_ptr_.reset(new object_type);
}
}
static std::once_flag once_;
}; };
template <typename _Ty> template <typename _Ty>
std::once_flag Singleton<_Ty>::once_; _Ty Singleton<_Ty>::instance_;
template <typename _Ty>
typename std::unique_ptr<_Ty> Singleton<_Ty>::instance_ptr_;
} // namespace kiwano } // namespace kiwano