MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / setThreadName

Function setThreadName

external/nvImageCodec/src/thread_pool.cpp:37–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 namespace {
36
37 void setThreadName(const char* name) {
38 // Limit the thread name to 15 characters plus null terminator
39 char tmp_name[16];
40 strncpy(tmp_name, name, sizeof(tmp_name) - 1);
41 tmp_name[sizeof(tmp_name) - 1] = '\0'; // Ensure null termination
42
43#ifdef _WIN32
44 DWORD threadId = GetCurrentThreadId();
45 nvtxNameOsThreadA(threadId, tmp_name);
46 HRESULT hr = SetThreadDescription(GetCurrentThread(), std::wstring(tmp_name, tmp_name + strlen(tmp_name)).c_str());
47 if (FAILED(hr)) {
48 std::cerr << "Failed to set thread description on Windows." << std::endl;
49 }
50#elif defined(__linux__)
51 nvtxNameOsThreadA(syscall(SYS_gettid), tmp_name);
52 pthread_setname_np(pthread_self(), tmp_name);
53#else
54 std::cerr << "Setting thread name not supported on this platform." << std::endl;
55#endif
56 }
57
58 } // namespace
59

Callers 1

threadMainMethod · 0.85

Calls 2

nvtxNameOsThreadAFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected