From f9348b8551cdc68caec247d7ad5b31ad6148c7b8 Mon Sep 17 00:00:00 2001 From: Nomango Date: Wed, 30 Sep 2020 19:03:39 +0800 Subject: [PATCH] [deploy] update singleton & FUCK msvc --- src/kiwano/core/Singleton.h | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/kiwano/core/Singleton.h b/src/kiwano/core/Singleton.h index 70158f86..f6141043 100644 --- a/src/kiwano/core/Singleton.h +++ b/src/kiwano/core/Singleton.h @@ -19,8 +19,6 @@ // THE SOFTWARE. #pragma once -#include -#include namespace kiwano { @@ -31,22 +29,14 @@ class Singleton public: using object_type = _Ty; - static std::unique_ptr instance_ptr_; - static inline object_type& GetInstance() { - return *GetInstancePtr(); + return instance_; } static inline object_type* GetInstancePtr() { - std::call_once(once_, Singleton::Init); - return instance_ptr_.get(); - } - - static inline void DestroyInstance() - { - instance_ptr_.reset(); + return &instance_; } protected: @@ -54,22 +44,10 @@ protected: Singleton(const Singleton&) = delete; Singleton& operator=(const Singleton&) = delete; -private: - static inline void Init() - { - if (!instance_ptr_) - { - instance_ptr_.reset(new object_type); - } - } - - static std::once_flag once_; + static _Ty instance_; }; template -std::once_flag Singleton<_Ty>::once_; - -template -typename std::unique_ptr<_Ty> Singleton<_Ty>::instance_ptr_; +_Ty Singleton<_Ty>::instance_; } // namespace kiwano