diff --git a/src/util/util_lazy.h b/src/util/util_lazy.h new file mode 100644 index 000000000..036636647 --- /dev/null +++ b/src/util/util_lazy.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +namespace dxvk { + + /** + * \brief Lazy-initialized object + * + * Creates an object on demand with + * the given constructor arguments. + */ + template + class Lazy { + + public: + + template + T& get(Args... args) { + if (m_object) + return *m_object; + + std::lock_guard lock(m_mutex); + + if (!m_object) { + m_object = std::make_unique( + std::forward(args)...); + } + + return *m_object; + } + + private: + + std::mutex m_mutex; + std::unique_ptr m_object; + + }; + +} \ No newline at end of file