Commit MetaInfo

Revisão61b564f6605037c1f7640766deaca054fbe9fdc3 (tree)
Hora2020-03-02 05:50:42
AutorSam Lantinga <slouken@libs...>
CommiterSam Lantinga

Mensagem de Log

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).

Mudança Sumário

Diff

diff -r ed7c27865ea7 -r 61b564f66050 src/thread/stdcpp/SDL_systhread.cpp
--- a/src/thread/stdcpp/SDL_systhread.cpp Thu Feb 27 13:53:32 2020 -0800
+++ b/src/thread/stdcpp/SDL_systhread.cpp Sun Mar 01 12:50:42 2020 -0800
@@ -96,19 +96,30 @@
9696 int
9797 SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
9898 {
99- // Thread priorities do not look to be settable via C++11's thread
100- // interface, at least as of this writing (Nov 2012). std::thread does
101- // provide access to the OS' native handle, however, and some form of
102- // priority-setting could, in theory, be done through this interface.
103- //
104- // WinRT: UPDATE (Aug 20, 2013): thread priorities cannot be changed
105- // on WinRT, at least not for any thread that's already been created.
106- // WinRT threads appear to be based off of the WinRT class,
107- // ThreadPool, more info on which can be found at:
108- // http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.aspx
109- //
110- // For compatibility sake, 0 will be returned here.
111- return (0);
99+#ifdef __WINRT__
100+ int value;
101+
102+ if (priority == SDL_THREAD_PRIORITY_LOW) {
103+ value = THREAD_PRIORITY_LOWEST;
104+ }
105+ else if (priority == SDL_THREAD_PRIORITY_HIGH) {
106+ value = THREAD_PRIORITY_HIGHEST;
107+ }
108+ else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
109+ // FIXME: WinRT does not support TIME_CRITICAL! -flibit
110+ SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "TIME_CRITICAL unsupported, falling back to HIGHEST");
111+ value = THREAD_PRIORITY_HIGHEST;
112+ }
113+ else {
114+ value = THREAD_PRIORITY_NORMAL;
115+ }
116+ if (!SetThreadPriority(GetCurrentThread(), value)) {
117+ return WIN_SetError("SetThreadPriority()");
118+ }
119+ return 0;
120+#else
121+ return SDL_Unsupported();
122+#endif
112123 }
113124
114125 extern "C"
Show on old repository browser