Browse Source

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

Ozkan Sezer 6 months ago
parent
commit
73a8143581
1 changed files with 5 additions and 8 deletions
  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"
 #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);
 typedef HANDLE (WINAPI *CreateWaitableTimerExW_t)(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess);
 static CreateWaitableTimerExW_t pCreateWaitableTimerExW;
 static CreateWaitableTimerExW_t pCreateWaitableTimerExW;
 
 
@@ -35,7 +40,6 @@ static void SDL_CleanupWaitableHandle(void *handle)
     CloseHandle(handle);
     CloseHandle(handle);
 }
 }
 
 
-#ifdef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
 static HANDLE SDL_GetWaitableTimer(void)
 static HANDLE SDL_GetWaitableTimer(void)
 {
 {
     static SDL_TLSID TLS_timer_handle;
     static SDL_TLSID TLS_timer_handle;
@@ -67,7 +71,6 @@ static HANDLE SDL_GetWaitableTimer(void)
     }
     }
     return timer;
     return timer;
 }
 }
-#endif // CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
 
 
 static HANDLE SDL_GetWaitableEvent(void)
 static HANDLE SDL_GetWaitableEvent(void)
 {
 {
@@ -102,11 +105,6 @@ Uint64 SDL_GetPerformanceFrequency(void)
 
 
 void SDL_SYS_DelayNS(Uint64 ns)
 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();
     HANDLE timer = SDL_GetWaitableTimer();
     if (timer) {
     if (timer) {
         LARGE_INTEGER due_time;
         LARGE_INTEGER due_time;
@@ -116,7 +114,6 @@ void SDL_SYS_DelayNS(Uint64 ns)
         }
         }
         return;
         return;
     }
     }
-#endif
 
 
     const Uint64 max_delay = 0xffffffffLL * SDL_NS_PER_MS;
     const Uint64 max_delay = 0xffffffffLL * SDL_NS_PER_MS;
     if (ns > max_delay) {
     if (ns > max_delay) {