thread/SafeSingleton: pass parameters to constructor
This commit is contained in:
parent
1fd8d46064
commit
5544375002
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user