We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4992 - UWP/WinRT does not set thread priority when using SDL_SetThreadPriority
Summary: UWP/WinRT does not set thread priority when using SDL_SetThreadPriority
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.10
Hardware: x86 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.12
Depends on:
Blocks:
 
Reported: 2020-02-18 03:57 UTC by Jeff Loiselle
Modified: 2020-03-01 20:51 UTC (History)
1 user (show)

See Also:


Attachments
Patch to implement WinRT SetThreadPriority (1.81 KB, patch)
2020-02-26 20:36 UTC, Ethan Lee
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Loiselle 2020-02-18 03:57:49 UTC
Thread priorities aren't being set in UWP/WinRT builds.  This was not initially possible in WinRT/UWP, however it is now possible.  This is affecting time sensitive threads like audio.  

NOTE:
Not all thread priorities appear to be valid for UWP.  I was unable to set a thread to real time, however I was able to set a thread to high (Highest in MS land).  

Docs for SetThreadPriority function:
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreadpriority
Comment 1 Sam Lantinga 2020-02-18 05:54:49 UTC
Do you have a tested patch for this? I know for earlier SDKs it was not possible to compile UWP code using SetThreadPriority.
Comment 2 Jeff Loiselle 2020-02-18 20:38:46 UTC
I do not.  We've got a workaround for our version of SDL, but we're only using it for UWP.  However our patch does not clamp priorities, so we also changed a few calls to make SDL use Highest instead of Realtime.  It also does not use the return value of SetThreadPriority as it's non-zero for success, instead of non-zero for failure which I believe is what SDL assumes.  

Our code is below with the following caveats:
1. Not ifdef'd for WinRT
2. Priorities above High will not be set.  (Setting to real time for instance will cause thread to remain normal priority).
3. Return code is not using return code of SetThreadPriority.

extern "C"
int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
    SetThreadPriority(GetCurrentThread(), priority);
    return (0);
}
Comment 3 Ryan C. Gordon 2020-02-18 22:43:17 UTC
We should bump this to 2.0.13.

--ryan.
Comment 4 Ethan Lee 2020-02-26 20:36:54 UTC
Created attachment 4230 [details]
Patch to implement WinRT SetThreadPriority

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).
Comment 5 Sam Lantinga 2020-03-01 20:51:20 UTC
Okay, Ethan, your patch is in for release.
https://hg.libsdl.org/SDL/rev/61b564f66050

Thanks!