Skip to content

Commit 04db07c

Browse files
authored
use NtDelayExecution for SDL_SYS_DelayNS
1 parent 98bed62 commit 04db07c

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/timer/windows/SDL_systimer.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,13 @@ Uint64 SDL_GetPerformanceFrequency(void)
103103
return (Uint64)frequency.QuadPart;
104104
}
105105

106+
NTSYSAPI NTSTATUS NTAPI NtDelayExecution( BOOLEAN Alertable, PLARGE_INTEGER DelayInterval );
106107
void SDL_SYS_DelayNS(Uint64 ns)
107108
{
108-
HANDLE timer = SDL_GetWaitableTimer();
109-
if (timer) {
110-
LARGE_INTEGER due_time;
111-
due_time.QuadPart = -((LONGLONG)ns / 100);
112-
if (pSetWaitableTimerEx(timer, &due_time, 0, NULL, NULL, NULL, 0)) {
113-
WaitForSingleObject(timer, INFINITE);
114-
}
115-
return;
116-
}
117-
118-
const Uint64 max_delay = 0xffffffffLL * SDL_NS_PER_MS;
119-
if (ns > max_delay) {
120-
ns = max_delay;
121-
}
122-
const DWORD delay = (DWORD)SDL_NS_TO_MS(ns);
123-
124-
HANDLE event = SDL_GetWaitableEvent();
125-
if (event) {
126-
WaitForSingleObjectEx(event, delay, FALSE);
127-
return;
128-
}
129-
130-
Sleep(delay);
109+
Sint64 tick = ns;
110+
tick /= 500;
111+
tick *= -1;
112+
NtDelayExecution(0, &tick);
131113
}
132114

133115
#endif // SDL_TIMER_WINDOWS

0 commit comments

Comments
 (0)