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.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
index ae13b9c..573bc42 100644
--- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
+++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
@@ -123,8 +123,7 @@
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\thread\SDL_systhread.h" />
<ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h" />
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h" />
+ <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
<ClInclude Include="..\..\src\timer\SDL_timer_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
@@ -240,11 +239,12 @@
<ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
<ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
<ClCompile Include="..\..\src\stdlib\SDL_string.c" />
- <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c" />
+ <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
<ClCompile Include="..\..\src\thread\SDL_thread.c" />
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp" />
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp" />
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_systls.c" />
<ClCompile Include="..\..\src\timer\SDL_timer.c" />
<ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
<ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
index b0e044d..907e1bf 100644
--- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
+++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
@@ -318,12 +318,6 @@
<ClInclude Include="..\..\src\thread\SDL_thread_c.h">
<Filter>Source Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h">
- <Filter>Source Files</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h">
- <Filter>Source Files</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\timer\SDL_timer_c.h">
<Filter>Source Files</Filter>
</ClInclude>
@@ -384,6 +378,9 @@
<ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h">
<Filter>Source Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -575,21 +572,9 @@
<ClCompile Include="..\..\src\stdlib\SDL_string.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\thread\SDL_thread.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\timer\SDL_timer.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -686,5 +671,20 @@
<ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_systls.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ 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 7665cc4..a56516e 100644
--- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj
+++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj
@@ -136,10 +136,8 @@
<ClInclude Include="..\..\src\SDL_fatal.h" />
<ClInclude Include="..\..\src\SDL_hints_c.h" />
<ClInclude Include="..\..\src\SDL_internal.h" />
- <ClInclude Include="..\..\src\thread\SDL_systhread.h" />
<ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h" />
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h" />
+ <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
<ClInclude Include="..\..\src\timer\SDL_timer_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
@@ -273,11 +271,12 @@
<ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
<ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
<ClCompile Include="..\..\src\stdlib\SDL_string.c" />
- <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c" />
+ <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
<ClCompile Include="..\..\src\thread\SDL_thread.c" />
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp" />
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp" />
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_systls.c" />
<ClCompile Include="..\..\src\timer\SDL_timer.c" />
<ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
<ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters
index 502f92c..a36811d 100644
--- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters
+++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters
@@ -312,18 +312,9 @@
<ClInclude Include="..\..\src\SDL_internal.h">
<Filter>Source Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\thread\SDL_systhread.h">
- <Filter>Source Files</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\thread\SDL_thread_c.h">
<Filter>Source Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_sysmutex_c.h">
- <Filter>Source Files</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\thread\stdcpp\SDL_systhread_c.h">
- <Filter>Source Files</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\timer\SDL_timer_c.h">
<Filter>Source Files</Filter>
</ClInclude>
@@ -399,6 +390,9 @@
<ClInclude Include="..\..\src\haptic\windows\SDL_windowshaptic_c.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h" />
+ <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -590,21 +584,9 @@
<ClCompile Include="..\..\src\stdlib\SDL_string.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\thread\generic\SDL_syssem.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\thread\SDL_thread.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\timer\SDL_timer.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -713,5 +695,20 @@
<ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_dinputhaptic.c" />
+ <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_systls.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h
index 2511ab9..4d29dba 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 a5c62cd..3b75ded 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 149c275..1f0a8df 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 34d70d4..9217ebc 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);
}