Repository: xbmc/xbmc
File: xbmc/platform/win32/threads/ThreadImplWin.cpp (C++)

Code before:
    }
    else
    {
      CLog::Log(LOGDEBUG, "[threads] name: '{}' priority: {}", m_name, native.name);
      bReturn = true;
    }
  }
  return bReturn;
}

bool CThreadImplWin::SetTask(const ThreadTask& task)
{
#ifdef TARGET_WINDOWS_DESKTOP
  std::call_once(flag, LogProcessPriorityClass);

  const std::wstring taskName{ThreadTaskToNativeTask(task)};
  m_hTask = AvSetMmThreadCharacteristicsW(taskName.c_str(), &m_taskIndex);
  if (m_hTask == 0)
  {
    CLog::LogF(LOGERROR, "unable to register thread with the multimedia scheduler ({})",
               GetLastError());
    return false;
  }

  CLog::Log(LOGDEBUG, "[threads] name: '{}' task: {}", m_name,
            std::string(taskName.begin(), taskName.end()));
#endif
  return true;
}

bool CThreadImplWin::RevertTask()
{
  bool ret{true};
#ifdef TARGET_WINDOWS_DESKTOP
  std::call_once(flag, LogProcessPriorityClass);

  if (m_hTask != 0)
  {
    if (AvRevertMmThreadCharacteristics(m_hTask) == 0)
    {
      CLog::LogF(LOGERROR, "unable to unregister thread from the multimedia scheduler ({})",
                 GetLastError());
      ret = false;
    }
    m_hTask = 0;

    CLog::Log(LOGDEBUG, "[threads] name: '{}' no task", m_name);
  }
#endif
  return ret;
}

Review comment (suggestion):
This code is for convert wstring to string?

Generates a lot of compile warnings:

```
1>        V:\kodi\xbmc\platform\win32\threads\ThreadImplWin.cpp(186,24):
1>        see reference to function template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Elem>>>,0>(_Iter,_Iter,const _Alloc &)' being compiled
1>        with
1>        [
1>            _Elem=wchar_t,
1>            _Iter=std::_String_const_iterator<std::_String_val<std::_Simple_types<wchar_t>>>,
1>            _Alloc=std::allocator<char>
1>        ]
1>            V:\kodi\xbmc\platform\win32\threads\ThreadImplWin.cpp(185,12):
1>            see the first reference to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string' in 'CThreadImplWin::SetTask'
1>        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\xstring(812,17):
1>        see reference to function template instantiation 'void std::basic_string<char,std::char_traits<char>,std::allocator<char>>::_Construct_from_iter<const wchar_t*,const wchar_t*,_Size_type>(_Iter,const _Sent,_Size)' being compiled
1>        with
1>        [
1>            _Size_type=unsigned __int64,
1>            _Iter=const wchar_t *,
1>            _Sent=const wchar_t *,
1>            _Size=unsigned __int64
1>        ]
1>        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\xstring(968,18):
1>        see reference to function template instantiation '_OutIt *std::_Copy_n_unchecked4<const wchar_t*,_Size,char*>(_InIt,_SizeTy,_OutIt)' being compiled
1>        with
1>        [
1>            _OutIt=char *,
1>            _Size=unsigned __int64,
1>            _InIt=const wchar_t *,
1>            _SizeTy=unsigned __int64
1>        ]
1>Done building project "libkodi.vcxproj".
```

Maybe is better use std::string for task definitions, log, etc. and only convert to std::wstring at time pass to Windows API (using `KODI::PLATFORM::WINDOWS::ToW`)

Code after:
    }
    else
    {
      CLog::Log(LOGDEBUG, "[threads] name: '{}' priority: {}", m_name, native.name);
      bReturn = true;
    }
  }
  return bReturn;
}

bool CThreadImplWin::SetTask(const ThreadTask& task)
{
#ifdef TARGET_WINDOWS_DESKTOP
  std::call_once(flag, LogProcessPriorityClass);

  std::string_view taskName{ThreadTaskToNativeTask(task)};

  using KODI::PLATFORM::WINDOWS::ToW;

  m_hTask = AvSetMmThreadCharacteristicsW(ToW(taskName).c_str(), &m_taskIndex);
  if (m_hTask == 0)
  {
    CLog::LogF(LOGERROR, "unable to register thread with the multimedia scheduler ({})",
               GetLastError());
    return false;
  }

  CLog::Log(LOGDEBUG, "[threads] name: '{}' task: {}", m_name, taskName);
#endif
  return true;
}

bool CThreadImplWin::RevertTask()
{
  bool ret{true};
#ifdef TARGET_WINDOWS_DESKTOP
  std::call_once(flag, LogProcessPriorityClass);

  if (m_hTask != 0)
  {
    if (AvRevertMmThreadCharacteristics(m_hTask) == 0)
    {
      CLog::LogF(LOGERROR, "unable to unregister thread from the multimedia scheduler ({})",
                 GetLastError());
      ret = false;
    }
    m_hTask = 0;

    CLog::Log(LOGDEBUG, "[threads] name: '{}' no task", m_name);
  }
#endif