MCPcopy Create free account
hub / github.com/crossuo/crossuo / SetThreadName

Function SetThreadName

external/tracy/common/TracySystem.cpp:101–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99#endif
100
101TRACY_API void SetThreadName( const char* name )
102{
103#if defined _WIN32 || defined __CYGWIN__
104 static auto _SetThreadDescription = (t_SetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "SetThreadDescription" );
105 if( _SetThreadDescription )
106 {
107 wchar_t buf[256];
108 mbstowcs( buf, name, 256 );
109 _SetThreadDescription( GetCurrentThread(), buf );
110 }
111 else
112 {
113# if defined _MSC_VER
114 const DWORD MS_VC_EXCEPTION=0x406D1388;
115# pragma pack( push, 8 )
116 struct THREADNAME_INFO
117 {
118 DWORD dwType;
119 LPCSTR szName;
120 DWORD dwThreadID;
121 DWORD dwFlags;
122 };
123# pragma pack(pop)
124
125 DWORD ThreadId = GetCurrentThreadId();
126 THREADNAME_INFO info;
127 info.dwType = 0x1000;
128 info.szName = name;
129 info.dwThreadID = ThreadId;
130 info.dwFlags = 0;
131
132 __try
133 {
134 RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
135 }
136 __except(EXCEPTION_EXECUTE_HANDLER)
137 {
138 }
139# endif
140 }
141#elif defined _GNU_SOURCE && !defined __EMSCRIPTEN__ && !defined __CYGWIN__
142 {
143 const auto sz = strlen( name );
144 if( sz <= 15 )
145 {
146 pthread_setname_np( pthread_self(), name );
147 }
148 else
149 {
150 char buf[16];
151 memcpy( buf, name, 15 );
152 buf[15] = '\0';
153 pthread_setname_np( pthread_self(), buf );
154 }
155 }
156#endif
157#ifdef TRACY_ENABLE
158 {

Callers 3

SysTraceWorkerFunction · 0.85
WorkerMethod · 0.85
CompressWorkerMethod · 0.85

Calls 6

pthread_selfFunction · 0.85
memcpyFunction · 0.85
InitRPMallocThreadFunction · 0.85
tracy_mallocFunction · 0.85
GetThreadHandleImplFunction · 0.85
loadMethod · 0.80

Tested by

no test coverage detected