WinRT: bug-fix - SDL_SetThreadPriority() didn't work on WinRT 8.x platforms
authorDavid Ludwig <dludwig@pobox.com>
Thu, 26 Nov 2015 13:51:03 -0500
changeset 993084285c1d8ca4
parent 9929 500c15a73ede
child 9931 0bb3dd1c95f2
WinRT: bug-fix - SDL_SetThreadPriority() didn't work on WinRT 8.x platforms

WinRT 8.0 (Phone and non-Phone) didn't offer an API to set an already-created
thread's priority. WinRT 8.1 offered this API, along with several other
Win32 thread functions that were previously unavailable (in WinRT).

This change makes WinRT 8.1+ platforms use SDL's Win32 backend.
VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj
VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters
include/SDL_config_winrt.h
src/thread/windows/SDL_sysmutex.c
src/thread/windows/SDL_syssem.c
src/thread/windows/SDL_systhread.c
     1.1 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj	Thu Nov 26 11:15:43 2015 -0500
     1.2 +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj	Thu Nov 26 13:51:03 2015 -0500
     1.3 @@ -123,8 +123,7 @@
     1.4      <ClInclude Include="..\..\src\SDL_internal.h" />
     1.5      <ClInclude Include="..\..\src\thread\SDL_systhread.h" />
     1.6      <ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
     1.7 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h" />
     1.8 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h" />
     1.9 +    <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
    1.10      <ClInclude Include="..\..\src\timer\SDL_timer_c.h" />
    1.11      <ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
    1.12      <ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
    1.13 @@ -240,11 +239,12 @@
    1.14      <ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
    1.15      <ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
    1.16      <ClCompile Include="..\..\src\stdlib\SDL_string.c" />
    1.17 -    <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c" />
    1.18 +    <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
    1.19      <ClCompile Include="..\..\src\thread\SDL_thread.c" />
    1.20 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp" />
    1.21 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp" />
    1.22 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp" />
    1.23 +    <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
    1.24 +    <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c" />
    1.25 +    <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c" />
    1.26 +    <ClCompile Include="..\..\src\thread\windows\SDL_systls.c" />
    1.27      <ClCompile Include="..\..\src\timer\SDL_timer.c" />
    1.28      <ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
    1.29      <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
     2.1 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters	Thu Nov 26 11:15:43 2015 -0500
     2.2 +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters	Thu Nov 26 13:51:03 2015 -0500
     2.3 @@ -318,12 +318,6 @@
     2.4      <ClInclude Include="..\..\src\thread\SDL_thread_c.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h">
     2.8 -      <Filter>Source Files</Filter>
     2.9 -    </ClInclude>
    2.10 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h">
    2.11 -      <Filter>Source Files</Filter>
    2.12 -    </ClInclude>
    2.13      <ClInclude Include="..\..\src\timer\SDL_timer_c.h">
    2.14        <Filter>Source Files</Filter>
    2.15      </ClInclude>
    2.16 @@ -384,6 +378,9 @@
    2.17      <ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h">
    2.18        <Filter>Source Files</Filter>
    2.19      </ClInclude>
    2.20 +    <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
    2.21 +      <Filter>Source Files</Filter>
    2.22 +    </ClInclude>
    2.23    </ItemGroup>
    2.24    <ItemGroup>
    2.25      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    2.26 @@ -575,21 +572,9 @@
    2.27      <ClCompile Include="..\..\src\stdlib\SDL_string.c">
    2.28        <Filter>Source Files</Filter>
    2.29      </ClCompile>
    2.30 -    <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c">
    2.31 -      <Filter>Source Files</Filter>
    2.32 -    </ClCompile>
    2.33      <ClCompile Include="..\..\src\thread\SDL_thread.c">
    2.34        <Filter>Source Files</Filter>
    2.35      </ClCompile>
    2.36 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp">
    2.37 -      <Filter>Source Files</Filter>
    2.38 -    </ClCompile>
    2.39 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp">
    2.40 -      <Filter>Source Files</Filter>
    2.41 -    </ClCompile>
    2.42 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp">
    2.43 -      <Filter>Source Files</Filter>
    2.44 -    </ClCompile>
    2.45      <ClCompile Include="..\..\src\timer\SDL_timer.c">
    2.46        <Filter>Source Files</Filter>
    2.47      </ClCompile>
    2.48 @@ -686,5 +671,20 @@
    2.49      <ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c">
    2.50        <Filter>Source Files</Filter>
    2.51      </ClCompile>
    2.52 +    <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c">
    2.53 +      <Filter>Source Files</Filter>
    2.54 +    </ClCompile>
    2.55 +    <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
    2.56 +      <Filter>Source Files</Filter>
    2.57 +    </ClCompile>
    2.58 +    <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c">
    2.59 +      <Filter>Source Files</Filter>
    2.60 +    </ClCompile>
    2.61 +    <ClCompile Include="..\..\src\thread\windows\SDL_systls.c">
    2.62 +      <Filter>Source Files</Filter>
    2.63 +    </ClCompile>
    2.64 +    <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
    2.65 +      <Filter>Source Files</Filter>
    2.66 +    </ClCompile>
    2.67    </ItemGroup>
    2.68  </Project>
    2.69 \ No newline at end of file
     3.1 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj	Thu Nov 26 11:15:43 2015 -0500
     3.2 +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj	Thu Nov 26 13:51:03 2015 -0500
     3.3 @@ -136,10 +136,8 @@
     3.4      <ClInclude Include="..\..\src\SDL_fatal.h" />
     3.5      <ClInclude Include="..\..\src\SDL_hints_c.h" />
     3.6      <ClInclude Include="..\..\src\SDL_internal.h" />
     3.7 -    <ClInclude Include="..\..\src\thread\SDL_systhread.h" />
     3.8      <ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
     3.9 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h" />
    3.10 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h" />
    3.11 +    <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
    3.12      <ClInclude Include="..\..\src\timer\SDL_timer_c.h" />
    3.13      <ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
    3.14      <ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
    3.15 @@ -273,11 +271,12 @@
    3.16      <ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
    3.17      <ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
    3.18      <ClCompile Include="..\..\src\stdlib\SDL_string.c" />
    3.19 -    <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c" />
    3.20 +    <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
    3.21      <ClCompile Include="..\..\src\thread\SDL_thread.c" />
    3.22 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp" />
    3.23 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp" />
    3.24 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp" />
    3.25 +    <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
    3.26 +    <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c" />
    3.27 +    <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c" />
    3.28 +    <ClCompile Include="..\..\src\thread\windows\SDL_systls.c" />
    3.29      <ClCompile Include="..\..\src\timer\SDL_timer.c" />
    3.30      <ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
    3.31      <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
     4.1 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters	Thu Nov 26 11:15:43 2015 -0500
     4.2 +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters	Thu Nov 26 13:51:03 2015 -0500
     4.3 @@ -312,18 +312,9 @@
     4.4      <ClInclude Include="..\..\src\SDL_internal.h">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClInclude>
     4.7 -    <ClInclude Include="..\..\src\thread\SDL_systhread.h">
     4.8 -      <Filter>Source Files</Filter>
     4.9 -    </ClInclude>
    4.10      <ClInclude Include="..\..\src\thread\SDL_thread_c.h">
    4.11        <Filter>Source Files</Filter>
    4.12      </ClInclude>
    4.13 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h">
    4.14 -      <Filter>Source Files</Filter>
    4.15 -    </ClInclude>
    4.16 -    <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h">
    4.17 -      <Filter>Source Files</Filter>
    4.18 -    </ClInclude>
    4.19      <ClInclude Include="..\..\src\timer\SDL_timer_c.h">
    4.20        <Filter>Source Files</Filter>
    4.21      </ClInclude>
    4.22 @@ -399,6 +390,9 @@
    4.23      <ClInclude Include="..\..\src\haptic\windows\SDL_windowshaptic_c.h" />
    4.24      <ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
    4.25      <ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h" />
    4.26 +    <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
    4.27 +      <Filter>Source Files</Filter>
    4.28 +    </ClInclude>
    4.29    </ItemGroup>
    4.30    <ItemGroup>
    4.31      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    4.32 @@ -590,21 +584,9 @@
    4.33      <ClCompile Include="..\..\src\stdlib\SDL_string.c">
    4.34        <Filter>Source Files</Filter>
    4.35      </ClCompile>
    4.36 -    <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c">
    4.37 -      <Filter>Source Files</Filter>
    4.38 -    </ClCompile>
    4.39      <ClCompile Include="..\..\src\thread\SDL_thread.c">
    4.40        <Filter>Source Files</Filter>
    4.41      </ClCompile>
    4.42 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp">
    4.43 -      <Filter>Source Files</Filter>
    4.44 -    </ClCompile>
    4.45 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp">
    4.46 -      <Filter>Source Files</Filter>
    4.47 -    </ClCompile>
    4.48 -    <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp">
    4.49 -      <Filter>Source Files</Filter>
    4.50 -    </ClCompile>
    4.51      <ClCompile Include="..\..\src\timer\SDL_timer.c">
    4.52        <Filter>Source Files</Filter>
    4.53      </ClCompile>
    4.54 @@ -713,5 +695,20 @@
    4.55      <ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
    4.56      <ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
    4.57      <ClCompile Include="..\..\src\haptic\windows\SDL_dinputhaptic.c" />
    4.58 +    <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c">
    4.59 +      <Filter>Source Files</Filter>
    4.60 +    </ClCompile>
    4.61 +    <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c">
    4.62 +      <Filter>Source Files</Filter>
    4.63 +    </ClCompile>
    4.64 +    <ClCompile Include="..\..\src\thread\windows\SDL_systls.c">
    4.65 +      <Filter>Source Files</Filter>
    4.66 +    </ClCompile>
    4.67 +    <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
    4.68 +      <Filter>Source Files</Filter>
    4.69 +    </ClCompile>
    4.70 +    <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
    4.71 +      <Filter>Source Files</Filter>
    4.72 +    </ClCompile>
    4.73    </ItemGroup>
    4.74  </Project>
    4.75 \ No newline at end of file
     5.1 --- a/include/SDL_config_winrt.h	Thu Nov 26 11:15:43 2015 -0500
     5.2 +++ b/include/SDL_config_winrt.h	Thu Nov 26 13:51:03 2015 -0500
     5.3 @@ -175,7 +175,12 @@
     5.4  #define SDL_LOADSO_WINDOWS	1
     5.5  
     5.6  /* Enable various threading systems */
     5.7 +#if (NTDDI_VERSION >= NTDDI_WINBLUE)
     5.8 +#define SDL_THREAD_WINDOWS  1
     5.9 +#else
    5.10 +/* WinRT on Windows 8.0 and Windows Phone 8.0 don't support CreateThread() */
    5.11  #define SDL_THREAD_STDCPP   1
    5.12 +#endif
    5.13  
    5.14  /* Enable various timer systems */
    5.15  #define SDL_TIMER_WINDOWS	1
     6.1 --- a/src/thread/windows/SDL_sysmutex.c	Thu Nov 26 11:15:43 2015 -0500
     6.2 +++ b/src/thread/windows/SDL_sysmutex.c	Thu Nov 26 13:51:03 2015 -0500
     6.3 @@ -45,7 +45,11 @@
     6.4      if (mutex) {
     6.5          /* Initialize */
     6.6          /* On SMP systems, a non-zero spin count generally helps performance */
     6.7 +#if __WINRT__
     6.8 +        InitializeCriticalSectionEx(&mutex->cs, 2000, 0);
     6.9 +#else
    6.10          InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
    6.11 +#endif
    6.12      } else {
    6.13          SDL_OutOfMemory();
    6.14      }
     7.1 --- a/src/thread/windows/SDL_syssem.c	Thu Nov 26 11:15:43 2015 -0500
     7.2 +++ b/src/thread/windows/SDL_syssem.c	Thu Nov 26 13:51:03 2015 -0500
     7.3 @@ -45,7 +45,11 @@
     7.4      sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
     7.5      if (sem) {
     7.6          /* Create the semaphore, with max value 32K */
     7.7 +#if __WINRT__
     7.8 +        sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
     7.9 +#else
    7.10          sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL);
    7.11 +#endif
    7.12          sem->count = initial_value;
    7.13          if (!sem->id) {
    7.14              SDL_SetError("Couldn't create semaphore");
    7.15 @@ -86,7 +90,11 @@
    7.16      } else {
    7.17          dwMilliseconds = (DWORD) timeout;
    7.18      }
    7.19 +#if __WINRT__
    7.20 +    switch (WaitForSingleObjectEx(sem->id, dwMilliseconds, FALSE)) {
    7.21 +#else
    7.22      switch (WaitForSingleObject(sem->id, dwMilliseconds)) {
    7.23 +#endif
    7.24      case WAIT_OBJECT_0:
    7.25          InterlockedDecrement(&sem->count);
    7.26          retval = 0;
     8.1 --- a/src/thread/windows/SDL_systhread.c	Thu Nov 26 11:15:43 2015 -0500
     8.2 +++ b/src/thread/windows/SDL_systhread.c	Thu Nov 26 13:51:03 2015 -0500
     8.3 @@ -106,7 +106,7 @@
     8.4                       pfnSDL_CurrentBeginThread pfnBeginThread,
     8.5                       pfnSDL_CurrentEndThread pfnEndThread)
     8.6  {
     8.7 -#elif defined(__CYGWIN__)
     8.8 +#elif defined(__CYGWIN__) || defined(__WINRT__)
     8.9  int
    8.10  SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
    8.11  {
    8.12 @@ -230,7 +230,11 @@
    8.13  void
    8.14  SDL_SYS_WaitThread(SDL_Thread * thread)
    8.15  {
    8.16 +#if __WINRT__
    8.17 +    WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
    8.18 +#else
    8.19      WaitForSingleObject(thread->handle, INFINITE);
    8.20 +#endif
    8.21      CloseHandle(thread->handle);
    8.22  }
    8.23