@@ -194,9 +194,16 @@ int Common::SetSelfThreadAffinity(int cpu_core) {
194194
195195int Common::SetThreadName (std::thread* t, const std::string& name) {
196196#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);
197203 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)) {
200207 return -1 ;
201208 }
202209 return 0 ;
@@ -211,9 +218,16 @@ int Common::SetThreadName(std::thread* t, const std::string& name) {
211218
212219int Common::SetSelfThreadName (const std::string& name) {
213220#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);
214227 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)) {
217231 return -1 ;
218232 }
219233 return 0 ;
0 commit comments