From fa2d5ab4972e369e1777e6de6d0cc92cac112273 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Thu, 26 Nov 2015 13:51:03 -0500 Subject: [PATCH] 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. --- .../WinPhone81_VS2013/SDL-WinPhone81.vcxproj | 12 +++--- .../SDL-WinPhone81.vcxproj.filters | 36 ++++++++--------- .../WinRT81_VS2013/SDL-WinRT81.vcxproj | 13 +++---- .../SDL-WinRT81.vcxproj.filters | 39 +++++++++---------- include/SDL_config_winrt.h | 5 +++ src/thread/windows/SDL_sysmutex.c | 4 ++ src/thread/windows/SDL_syssem.c | 8 ++++ src/thread/windows/SDL_systhread.c | 6 ++- 8 files changed, 70 insertions(+), 53 deletions(-) diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj index ae13b9ccc41de..573bc4286ca3a 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj @@ -123,8 +123,7 @@ - - + @@ -240,11 +239,12 @@ - + - - - + + + + diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters index b0e044d51ea51..907e1bfb7f92d 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters @@ -318,12 +318,6 @@ Source Files - - Source Files - - - Source Files - Source Files @@ -384,6 +378,9 @@ Source Files + + Source Files + @@ -575,21 +572,9 @@ Source Files - - Source Files - Source Files - - Source Files - - - Source Files - - - Source Files - Source Files @@ -686,5 +671,20 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj index 7665cc4739c75..a56516ead6539 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj @@ -136,10 +136,8 @@ - - - + @@ -273,11 +271,12 @@ - + - - - + + + + diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters index 502f92cf65aa9..a36811dd4b19d 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters @@ -312,18 +312,9 @@ Source Files - - Source Files - Source Files - - Source Files - - - Source Files - Source Files @@ -399,6 +390,9 @@ + + Source Files + @@ -590,21 +584,9 @@ Source Files - - Source Files - Source Files - - Source Files - - - Source Files - - - Source Files - Source Files @@ -713,5 +695,20 @@ + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h index 2511ab9fa5631..4d29dba2446ab 100644 --- a/include/SDL_config_winrt.h +++ b/include/SDL_config_winrt.h @@ -175,7 +175,12 @@ typedef unsigned int uintptr_t; #define SDL_LOADSO_WINDOWS 1 /* Enable various threading systems */ +#if (NTDDI_VERSION >= NTDDI_WINBLUE) +#define SDL_THREAD_WINDOWS 1 +#else +/* WinRT on Windows 8.0 and Windows Phone 8.0 don't support CreateThread() */ #define SDL_THREAD_STDCPP 1 +#endif /* Enable various timer systems */ #define SDL_TIMER_WINDOWS 1 diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index a5c62cd5afa4e..3b75ded8f82f3 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -45,7 +45,11 @@ SDL_CreateMutex(void) if (mutex) { /* Initialize */ /* On SMP systems, a non-zero spin count generally helps performance */ +#if __WINRT__ + InitializeCriticalSectionEx(&mutex->cs, 2000, 0); +#else InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000); +#endif } else { SDL_OutOfMemory(); } diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 149c275775206..1f0a8dfc796c6 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -45,7 +45,11 @@ SDL_CreateSemaphore(Uint32 initial_value) sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); if (sem) { /* Create the semaphore, with max value 32K */ +#if __WINRT__ + sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS); +#else sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL); +#endif sem->count = initial_value; if (!sem->id) { SDL_SetError("Couldn't create semaphore"); @@ -86,7 +90,11 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) } else { dwMilliseconds = (DWORD) timeout; } +#if __WINRT__ + switch (WaitForSingleObjectEx(sem->id, dwMilliseconds, FALSE)) { +#else switch (WaitForSingleObject(sem->id, dwMilliseconds)) { +#endif case WAIT_OBJECT_0: InterlockedDecrement(&sem->count); retval = 0; diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index 34d70d45bb705..9217ebc3df494 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -106,7 +106,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) { -#elif defined(__CYGWIN__) +#elif defined(__CYGWIN__) || defined(__WINRT__) int SDL_SYS_CreateThread(SDL_Thread * thread, void *args) { @@ -230,7 +230,11 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) void SDL_SYS_WaitThread(SDL_Thread * thread) { +#if __WINRT__ + WaitForSingleObjectEx(thread->handle, INFINITE, FALSE); +#else WaitForSingleObject(thread->handle, INFINITE); +#endif CloseHandle(thread->handle); }