| 1887 | // (Windows 10 1607 and later) is looked up, not linked: older SDKs and toolchains lack the import. |
| 1888 | namespace strata::platform { |
| 1889 | void name_this_thread(const char* base, int index) { |
| 1890 | char name[64]; |
| 1891 | if (index >= 0) std::snprintf(name, sizeof name, "%s-%d", base, index); |
| 1892 | else std::snprintf(name, sizeof name, "%s", base); |
| 1893 | using SetDesc = HRESULT(WINAPI*)(HANDLE, PCWSTR); |
| 1894 | static const SetDesc fn = (SetDesc) GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetThreadDescription"); |
| 1895 | if (fn == nullptr) return; |
| 1896 | wchar_t wide[64]; |
| 1897 | int i = 0; |
| 1898 | for (; name[i] != '\0' && i < 63; ++i) wide[i] = (wchar_t) (unsigned char) name[i]; |
| 1899 | wide[i] = L'\0'; |
| 1900 | (void) fn(GetCurrentThread(), wide); |
| 1901 | } |
| 1902 | } // namespace strata::platform |
| 1903 | #endif |
no test coverage detected