Skip to content

Commit 4b0514f

Browse files
whrvtslouken
authored andcommitted
Make use of GetQueueStatus' result in the Windows raw input loop.
Instead of only using it for the side effect of making MsgWaitForMultipleObjects block on the next call. This has the added benefit of avoiding an extra MsgWaitForMultipleObjects call if there was actually new raw input in the queue already.
1 parent 029746a commit 4b0514f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/video/windows/SDL_windowsrawinput.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
100100
// Tell the parent we're ready to go!
101101
SetEvent(data->ready_event);
102102

103-
while (!data->done) {
104-
Uint64 idle_begin = SDL_GetTicksNS();
105-
DWORD result = MsgWaitForMultipleObjects(1, &data->done_event, FALSE, INFINITE, QS_RAWINPUT);
106-
Uint64 idle_end = SDL_GetTicksNS();
107-
if (result != (WAIT_OBJECT_0 + 1)) {
108-
break;
109-
}
110-
111-
// Clear the queue status so MsgWaitForMultipleObjects() will wait again
112-
(void)GetQueueStatus(QS_RAWINPUT);
103+
Uint64 idle_begin = SDL_GetTicksNS();
104+
while (!data->done &&
105+
// The high-order word of GetQueueStatus() will let us know if there's currently raw input to be processed.
106+
// If there isn't, then we'll wait for new data to arrive with MsgWaitForMultipleObjects().
107+
((HIWORD(GetQueueStatus(QS_RAWINPUT)) & QS_RAWINPUT) ||
108+
(MsgWaitForMultipleObjects(1, &data->done_event, FALSE, INFINITE, QS_RAWINPUT) == WAIT_OBJECT_0 + 1))) {
113109

110+
Uint64 idle_end = SDL_GetTicksNS();
114111
Uint64 idle_time = idle_end - idle_begin;
115112
Uint64 usb_8khz_interval = SDL_US_TO_NS(125);
116113
Uint64 poll_start = idle_time < usb_8khz_interval ? _this->internal->last_rawinput_poll : idle_end;
117114

118115
WIN_PollRawInput(_this, poll_start);
116+
117+
// Reset idle_begin for the next go-around
118+
idle_begin = SDL_GetTicksNS();
119119
}
120120

121121
if (_this->internal->raw_input_fake_pen_id) {

0 commit comments

Comments
 (0)