thread/SafeSingleton: pass parameters to constructor

This commit is contained in:
Max Kellermann 2018-01-02 12:26:53 +01:00
parent 1fd8d46064
commit 5544375002

View File

@ -37,11 +37,12 @@ class SafeSingleton {
static T *instance;
public:
SafeSingleton() {
template<typename... Args>
explicit SafeSingleton(Args&&... args) {
const std::lock_guard<Mutex> lock(mutex);
if (ref == 0)
instance = new T;
instance = new T(std::forward<Args>(args)...);
/* increment after creating the instance; this way is
exception-safe, because we must not increment the