Parcourir la source

timer, windows: allow building high resolution code with old SDKs.

Ozkan Sezer il y a 2 mois
Parent
commit
73a8143581
1 fichiers modifiés avec 5 ajouts et 8 suppressions
  1. 5 8
      src/timer/windows/SDL_systimer.c

+ 5 - 8
src/timer/windows/SDL_systimer.c

@@ -24,6 +24,11 @@
 
 #include "../../core/windows/SDL_windows.h"
 
+/* CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag was added in Windows 10 version 1803. */
+#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
+#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x2
+#endif
+
 typedef HANDLE (WINAPI *CreateWaitableTimerExW_t)(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess);
 static CreateWaitableTimerExW_t pCreateWaitableTimerExW;
 
@@ -35,7 +40,6 @@ static void SDL_CleanupWaitableHandle(void *handle)
     CloseHandle(handle);
 }
 
-#ifdef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
 static HANDLE SDL_GetWaitableTimer(void)
 {
     static SDL_TLSID TLS_timer_handle;
@@ -67,7 +71,6 @@ static HANDLE SDL_GetWaitableTimer(void)
     }
     return timer;
 }
-#endif // CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
 
 static HANDLE SDL_GetWaitableEvent(void)
 {
@@ -102,11 +105,6 @@ Uint64 SDL_GetPerformanceFrequency(void)
 
 void SDL_SYS_DelayNS(Uint64 ns)
 {
-    /* CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag was added in Windows 10 version 1803.
-     *
-     * Use the compiler version to determine availability.
-     */
-#ifdef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
     HANDLE timer = SDL_GetWaitableTimer();
     if (timer) {
         LARGE_INTEGER due_time;
@@ -116,7 +114,6 @@ void SDL_SYS_DelayNS(Uint64 ns)
         }
         return;
     }
-#endif
 
     const Uint64 max_delay = 0xffffffffLL * SDL_NS_PER_MS;
     if (ns > max_delay) {