From 5544375002c582e43246ac7e70aa5e6e3c8c3654 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 2 Jan 2018 12:26:53 +0100 Subject: [PATCH] thread/SafeSingleton: pass parameters to constructor --- src/thread/SafeSingleton.hxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/thread/SafeSingleton.hxx b/src/thread/SafeSingleton.hxx index ce2f4bb81..386c1f376 100644 --- a/src/thread/SafeSingleton.hxx +++ b/src/thread/SafeSingleton.hxx @@ -37,11 +37,12 @@ class SafeSingleton { static T *instance; public: - SafeSingleton() { + template + explicit SafeSingleton(Args&&... args) { const std::lock_guard lock(mutex); if (ref == 0) - instance = new T; + instance = new T(std::forward(args)...); /* increment after creating the instance; this way is exception-safe, because we must not increment the