blob: f17febb831527a845018bc666fb5609c98ffc30f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
};
}
|