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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/src/thread/stdcpp/SDL_systhread.cpp b/src/thread/stdcpp/SDL_systhread.cpp
index 785abf2..fc839d3 100644
--- a/src/thread/stdcpp/SDL_systhread.cpp
+++ b/src/thread/stdcpp/SDL_systhread.cpp
@@ -96,19 +96,30 @@ extern "C"
int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
- // Thread priorities do not look to be settable via C++11's thread
- // interface, at least as of this writing (Nov 2012). std::thread does
- // provide access to the OS' native handle, however, and some form of
- // priority-setting could, in theory, be done through this interface.
- //
- // WinRT: UPDATE (Aug 20, 2013): thread priorities cannot be changed
- // on WinRT, at least not for any thread that's already been created.
- // WinRT threads appear to be based off of the WinRT class,
- // ThreadPool, more info on which can be found at:
- // http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.aspx
- //
- // For compatibility sake, 0 will be returned here.
- return (0);
+#ifdef __WINRT__
+ int value;
+
+ if (priority == SDL_THREAD_PRIORITY_LOW) {
+ value = THREAD_PRIORITY_LOWEST;
+ }
+ else if (priority == SDL_THREAD_PRIORITY_HIGH) {
+ value = THREAD_PRIORITY_HIGHEST;
+ }
+ else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
+ // FIXME: WinRT does not support TIME_CRITICAL! -flibit
+ SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "TIME_CRITICAL unsupported, falling back to HIGHEST");
+ 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"