mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-30 02:52:10 +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)
|
||||
: m_proc(std::move(proc)) {
|
||||
// Reference for the thread function
|
||||
this->incRef();
|
||||
|
||||
m_handle = ::CreateThread(nullptr, 0,
|
||||
ThreadFn::threadProc, this, 0, nullptr);
|
||||
|
||||
@ -59,8 +62,9 @@ namespace dxvk {
|
||||
HANDLE m_handle;
|
||||
|
||||
static DWORD WINAPI threadProc(void *arg) {
|
||||
Rc<ThreadFn> info = reinterpret_cast<ThreadFn*>(arg);
|
||||
info->m_proc();
|
||||
auto thread = reinterpret_cast<ThreadFn*>(arg);
|
||||
thread->m_proc();
|
||||
thread->decRef();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user