diff options
| author | 2023-10-20 11:41:29 -0400 | |
|---|---|---|
| committer | 2023-10-20 11:41:29 -0400 | |
| commit | 59b62c6507cdde382c25e135f4ca082aa3f964cb (patch) | |
| tree | a2cdbd6dc637d4f5502c7956c8199e6644132fef /src/common/thread.cpp | |
| parent | Merge pull request #11822 from german77/no-name (diff) | |
| download | yuzu-59b62c6507cdde382c25e135f4ca082aa3f964cb.tar.gz yuzu-59b62c6507cdde382c25e135f4ca082aa3f964cb.tar.xz yuzu-59b62c6507cdde382c25e135f4ca082aa3f964cb.zip | |
common: use SetThreadDescription API for thread names
Diffstat (limited to 'src/common/thread.cpp')
| -rw-r--r-- | src/common/thread.cpp | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 919e33af9..34cc1527b 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <mach/mach.h> | 11 | #include <mach/mach.h> |
| 12 | #elif defined(_WIN32) | 12 | #elif defined(_WIN32) |
| 13 | #include <windows.h> | 13 | #include <windows.h> |
| 14 | #include "common/string_util.h" | ||
| 14 | #else | 15 | #else |
| 15 | #if defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) | 16 | #if defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
| 16 | #include <pthread_np.h> | 17 | #include <pthread_np.h> |
| @@ -82,29 +83,8 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { | |||
| 82 | #ifdef _MSC_VER | 83 | #ifdef _MSC_VER |
| 83 | 84 | ||
| 84 | // Sets the debugger-visible name of the current thread. | 85 | // Sets the debugger-visible name of the current thread. |
| 85 | // Uses trick documented in: | ||
| 86 | // https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code | ||
| 87 | void SetCurrentThreadName(const char* name) { | 86 | void SetCurrentThreadName(const char* name) { |
| 88 | static const DWORD MS_VC_EXCEPTION = 0x406D1388; | 87 | SetThreadDescription(GetCurrentThread(), UTF8ToUTF16W(name).data()); |
| 89 | |||
| 90 | #pragma pack(push, 8) | ||
| 91 | struct THREADNAME_INFO { | ||
| 92 | DWORD dwType; // must be 0x1000 | ||
| 93 | LPCSTR szName; // pointer to name (in user addr space) | ||
| 94 | DWORD dwThreadID; // thread ID (-1=caller thread) | ||
| 95 | DWORD dwFlags; // reserved for future use, must be zero | ||
| 96 | } info; | ||
| 97 | #pragma pack(pop) | ||
| 98 | |||
| 99 | info.dwType = 0x1000; | ||
| 100 | info.szName = name; | ||
| 101 | info.dwThreadID = std::numeric_limits<DWORD>::max(); | ||
| 102 | info.dwFlags = 0; | ||
| 103 | |||
| 104 | __try { | ||
| 105 | RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); | ||
| 106 | } __except (EXCEPTION_CONTINUE_EXECUTION) { | ||
| 107 | } | ||
| 108 | } | 88 | } |
| 109 | 89 | ||
| 110 | #else // !MSVC_VER, so must be POSIX threads | 90 | #else // !MSVC_VER, so must be POSIX threads |