summaryrefslogtreecommitdiffstats
path: root/src/libs/dxvk-native-1.9.2a/src/util/util_lazy.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dxvk-native-1.9.2a/src/util/util_lazy.h')
-rw-r--r--src/libs/dxvk-native-1.9.2a/src/util/util_lazy.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libs/dxvk-native-1.9.2a/src/util/util_lazy.h b/src/libs/dxvk-native-1.9.2a/src/util/util_lazy.h
new file mode 100644
index 00000000..f17febb8
--- /dev/null
+++ b/src/libs/dxvk-native-1.9.2a/src/util/util_lazy.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <mutex>
+
+namespace dxvk {
+
+ /**
+ * \brief Lazy-initialized object
+ *
+ * Creates an object on demand with
+ * the given constructor arguments.
+ */
+ template<typename T>
+ class Lazy {
+
+ public:
+
+ template<typename... Args>
+ T& get(Args... args) {
+ if (m_object)
+ return *m_object;
+
+ std::lock_guard lock(m_mutex);
+
+ if (!m_object) {
+ m_object = std::make_unique<T>(
+ std::forward<Args>(args)...);
+ }
+
+ return *m_object;
+ }
+
+ private:
+
+ dxvk::mutex m_mutex;
+ std::unique_ptr<T> m_object;
+
+ };
+
+} \ No newline at end of file