-
Notifications
You must be signed in to change notification settings - Fork 899
/
Copy pathd3d8_multithread.h
77 lines (54 loc) · 1.26 KB
/
d3d8_multithread.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include "d3d8_include.h"
namespace dxvk {
/**
* \brief Device lock
*
* Lightweight RAII wrapper that implements
* a subset of the functionality provided by
* \c std::unique_lock, with the goal of being
* cheaper to construct and destroy.
*/
class D3D8DeviceLock {
public:
D3D8DeviceLock()
: m_mutex(nullptr) { }
D3D8DeviceLock(sync::RecursiveSpinlock& mutex)
: m_mutex(&mutex) {
mutex.lock();
}
D3D8DeviceLock(D3D8DeviceLock&& other)
: m_mutex(other.m_mutex) {
other.m_mutex = nullptr;
}
D3D8DeviceLock& operator = (D3D8DeviceLock&& other) {
if (m_mutex)
m_mutex->unlock();
m_mutex = other.m_mutex;
other.m_mutex = nullptr;
return *this;
}
~D3D8DeviceLock() {
if (m_mutex != nullptr)
m_mutex->unlock();
}
private:
sync::RecursiveSpinlock* m_mutex;
};
/**
* \brief D3D8 context lock
*/
class D3D8Multithread {
public:
D3D8Multithread(
BOOL Protected);
D3D8DeviceLock AcquireLock() {
return m_protected
? D3D8DeviceLock(m_mutex)
: D3D8DeviceLock();
}
private:
BOOL m_protected;
sync::RecursiveSpinlock m_mutex;
};
}