Fixed bug 4992 - UWP/WinRT does not set thread priority when using SDL_SetThreadPriority

Ethan Lee

Attached is a diff that I used to get SetThreadPriority working locally. I still have no idea what the minimum SDK version is since Microsoft never documented it, but it's worth pointing out that they're much more aggressive about using the latest VS and UWP SDK anyway (for example, an updated Xbox is no longer compatible with VS2017, and updates are required to have a network connection of any kind).
Sam Lantinga 2020-03-01 12:50:42 -08:00
parent 1af31a26d1
commit bd5da73afd
1 changed files with 24 additions and 13 deletions

View File

@ -96,19 +96,30 @@ extern "C"
int int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{ {
// Thread priorities do not look to be settable via C++11's thread #ifdef __WINRT__
// interface, at least as of this writing (Nov 2012). std::thread does int value;
// provide access to the OS' native handle, however, and some form of
// priority-setting could, in theory, be done through this interface. if (priority == SDL_THREAD_PRIORITY_LOW) {
// value = THREAD_PRIORITY_LOWEST;
// WinRT: UPDATE (Aug 20, 2013): thread priorities cannot be changed }
// on WinRT, at least not for any thread that's already been created. else if (priority == SDL_THREAD_PRIORITY_HIGH) {
// WinRT threads appear to be based off of the WinRT class, value = THREAD_PRIORITY_HIGHEST;
// ThreadPool, more info on which can be found at: }
// http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.aspx else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
// // FIXME: WinRT does not support TIME_CRITICAL! -flibit
// For compatibility sake, 0 will be returned here. SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "TIME_CRITICAL unsupported, falling back to HIGHEST");
return (0); value = THREAD_PRIORITY_HIGHEST;
}
else {
value = THREAD_PRIORITY_NORMAL;
}
if (!SetThreadPriority(GetCurrentThread(), value)) {
return WIN_SetError("SetThreadPriority()");
}
return 0;
#else
return SDL_Unsupported();
#endif
} }
extern "C" extern "C"