From 075bf87798041d00f95762aad443120089be270a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 16 Aug 2017 09:38:22 +0200 Subject: [PATCH] fix(Singleton): better code --- src/object/singleton.h | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/object/singleton.h b/src/object/singleton.h index 2a97c6609..667f71f9b 100644 --- a/src/object/singleton.h +++ b/src/object/singleton.h @@ -31,31 +31,17 @@ public: virtual ~Singleton () = default; static T *getInstance () { - if (!mInstance) { - mInstance = new T(); - static SingletonDeleter deleter; - } - return mInstance; + static T instance; + return &instance; } protected: explicit Singleton (ObjectPrivate &p) : Object(p) {} private: - struct SingletonDeleter { - ~SingletonDeleter () { - delete mInstance; - } - }; - - static T *mInstance; - L_DISABLE_COPY(Singleton); }; -template -T *Singleton::mInstance = nullptr; - LINPHONE_END_NAMESPACE #endif // ifndef _SINGLETON_H_