mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-06 22:54:16 +01:00
[util] Fix reference counting for thread objects
Fixes a potential race when threads run out of scope before the thread function has started.
This commit is contained in:
parent
e4c5880ac6
commit
2b8c96fe35
@ -26,6 +26,9 @@ namespace dxvk {
|
|||||||
|
|
||||||
ThreadFn(Proc&& proc)
|
ThreadFn(Proc&& proc)
|
||||||
: m_proc(std::move(proc)) {
|
: m_proc(std::move(proc)) {
|
||||||
|
// Reference for the thread function
|
||||||
|
this->incRef();
|
||||||
|
|
||||||
m_handle = ::CreateThread(nullptr, 0,
|
m_handle = ::CreateThread(nullptr, 0,
|
||||||
ThreadFn::threadProc, this, 0, nullptr);
|
ThreadFn::threadProc, this, 0, nullptr);
|
||||||
|
|
||||||
@ -59,8 +62,9 @@ namespace dxvk {
|
|||||||
HANDLE m_handle;
|
HANDLE m_handle;
|
||||||
|
|
||||||
static DWORD WINAPI threadProc(void *arg) {
|
static DWORD WINAPI threadProc(void *arg) {
|
||||||
Rc<ThreadFn> info = reinterpret_cast<ThreadFn*>(arg);
|
auto thread = reinterpret_cast<ThreadFn*>(arg);
|
||||||
info->m_proc();
|
thread->m_proc();
|
||||||
|
thread->decRef();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user