mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-14 09:23:53 +01:00
e884413c49
All our other threads have been destroyed and we can no longer synchronize with them properly. Co-authored-by: Paul Gofman <pgofman@codeweavers.com>
43 lines
1003 B
C++
43 lines
1003 B
C++
#include "thread.h"
|
|
#include "util_likely.h"
|
|
|
|
#include <atomic>
|
|
|
|
#ifdef _WIN32
|
|
|
|
namespace dxvk::this_thread {
|
|
|
|
bool isInModuleDetachment() {
|
|
using PFN_RtlDllShutdownInProgress = BOOLEAN (WINAPI *)();
|
|
|
|
static auto RtlDllShutdownInProgress = reinterpret_cast<PFN_RtlDllShutdownInProgress>(
|
|
::GetProcAddress(::GetModuleHandleW(L"ntdll.dll"), "RtlDllShutdownInProgress"));
|
|
|
|
return RtlDllShutdownInProgress();
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
namespace dxvk::this_thread {
|
|
|
|
static std::atomic<uint32_t> g_threadCtr = { 0u };
|
|
static thread_local uint32_t g_threadId = 0u;
|
|
|
|
// This implementation returns thread ids unique to the current instance.
|
|
// ie. if you use this across multiple .so's then you might get conflicting ids.
|
|
//
|
|
// This isn't an issue for us, as it is only used by the spinlock implementation,
|
|
// but may be for you if you use this elsewhere.
|
|
uint32_t get_id() {
|
|
if (unlikely(!g_threadId))
|
|
g_threadId = ++g_threadCtr;
|
|
|
|
return g_threadId;
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|