@@ -194,9 +194,16 @@ int Common::SetSelfThreadAffinity(int cpu_core) {
194
194
195
195
int Common::SetThreadName (std::thread* t, const std::string& name) {
196
196
#if defined(MYFRAME_OS_WINDOWS)
197
+ int len = MultiByteToWideChar (CP_UTF8, 0 , name.c_str (), -1 , nullptr , 0 );
198
+ if (len <= 0 ) {
199
+ return -1 ;
200
+ }
201
+ wchar_t * wide_name = new wchar_t [len];
202
+ MultiByteToWideChar (CP_UTF8, 0 , name.c_str (), -1 , wide_name, len);
197
203
auto handle = t->native_handle ();
198
- auto res = SetThreadDescription (handle, name.c_str ());
199
- if (res != 0 ) {
204
+ auto res = SetThreadDescription (handle, wide_name);
205
+ delete[] wide_name;
206
+ if (FAILED (res)) {
200
207
return -1 ;
201
208
}
202
209
return 0 ;
@@ -211,9 +218,16 @@ int Common::SetThreadName(std::thread* t, const std::string& name) {
211
218
212
219
int Common::SetSelfThreadName (const std::string& name) {
213
220
#if defined(MYFRAME_OS_WINDOWS)
221
+ int len = MultiByteToWideChar (CP_UTF8, 0 , name.c_str (), -1 , nullptr , 0 );
222
+ if (len <= 0 ) {
223
+ return -1 ;
224
+ }
225
+ wchar_t * wide_name = new wchar_t [len];
226
+ MultiByteToWideChar (CP_UTF8, 0 , name.c_str (), -1 , wide_name, len);
214
227
auto handle = GetCurrentThread ();
215
- auto res = SetThreadDescription (handle, name.c_str ());
216
- if (res != 0 ) {
228
+ auto res = SetThreadDescription (handle, wide_name);
229
+ delete[] wide_name;
230
+ if (FAILED (res)) {
217
231
return -1 ;
218
232
}
219
233
return 0 ;
0 commit comments