fix(Singleton): better code

This commit is contained in:
Ronan Abhamon 2017-08-16 09:38:22 +02:00
parent e4415e9b16
commit 075bf87798

View file

@ -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<class T>
T *Singleton<T>::mInstance = nullptr;
LINPHONE_END_NAMESPACE
#endif // ifndef _SINGLETON_H_