Commit 55443750 authored by Max Kellermann's avatar Max Kellermann

thread/SafeSingleton: pass parameters to constructor

parent 1fd8d460
...@@ -37,11 +37,12 @@ class SafeSingleton { ...@@ -37,11 +37,12 @@ class SafeSingleton {
static T *instance; static T *instance;
public: public:
SafeSingleton() { template<typename... Args>
explicit SafeSingleton(Args&&... args) {
const std::lock_guard<Mutex> lock(mutex); const std::lock_guard<Mutex> lock(mutex);
if (ref == 0) if (ref == 0)
instance = new T; instance = new T(std::forward<Args>(args)...);
/* increment after creating the instance; this way is /* increment after creating the instance; this way is
exception-safe, because we must not increment the exception-safe, because we must not increment the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment