@@ -20,12 +20,43 @@ void set_thread_realtime(std::thread& t, int prio, bool algo_fifo)
2020{
2121 auto hdl = reinterpret_cast <HANDLE >(t.native_handle ());
2222
23- SetPriorityClass (hdl, REALTIME_PRIORITY_CLASS );
24- SetThreadPriority (hdl, THREAD_PRIORITY_TIME_CRITICAL );
23+ auto err = SetThreadPriority (hdl, THREAD_PRIORITY_TIME_CRITICAL );
24+ if (err == 0 )
25+ SetThreadPriority (hdl, THREAD_PRIORITY_HIGHEST );
2526}
2627
27- void set_thread_name (std::thread& t, std::string_view name) { }
28- void set_thread_name (std::string_view name) { }
28+ void set_thread_name (std::thread& t, std::string_view name)
29+ {
30+ auto hdl = reinterpret_cast <HANDLE >(t.native_handle ());
31+ std::wstring wname;
32+ if (!name.empty ())
33+ {
34+ const int sizeNeeded = MultiByteToWideChar (CP_UTF8 , 0 , name.data (), name.size (), nullptr , 0 );
35+ if (sizeNeeded > 0 ) {
36+ wname.resize (sizeNeeded);
37+ MultiByteToWideChar (CP_UTF8 , 0 , name.data (), name.size (), wname.data (), sizeNeeded);
38+ }
39+ }
40+ SetThreadDescription (hdl, wname.data ());
41+ }
42+
43+ void set_thread_name (std::string_view name)
44+ {
45+ auto hdl = GetCurrentThread ();
46+ if (!hdl)
47+ return ;
48+
49+ std::wstring wname;
50+ if (!name.empty ())
51+ {
52+ const int sizeNeeded = MultiByteToWideChar (CP_UTF8 , 0 , name.data (), name.size (), nullptr , 0 );
53+ if (sizeNeeded > 0 ) {
54+ wname.resize (sizeNeeded);
55+ MultiByteToWideChar (CP_UTF8 , 0 , name.data (), name.size (), wname.data (), sizeNeeded);
56+ }
57+ }
58+ SetThreadDescription (hdl, wname.data ());
59+ }
2960void set_thread_pinned (std::thread& t, int cpu) { }
3061void set_thread_pinned (int cpu) { }
3162
0 commit comments