Call SDL_SendWakeupEvent() directly from SDL_PeepEvent() SDL_PeepEvent() is a documented public API, so we must properly support waking a waiting thread in SDL_WaitEventTimeout() with SDL_PeepEvent().
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
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 7f34cbc..4f8f91c 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -586,6 +586,24 @@ SDL_CutEvent(SDL_EventEntry *entry)
SDL_AtomicAdd(&SDL_EventQ.count, -1);
}
+static int
+SDL_SendWakeupEvent()
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (!_this || !_this->SendWakeupEvent) {
+ return 0;
+ }
+ if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
+ if (_this->wakeup_window && _this->blocking_thread_id != 0 && _this->blocking_thread_id != SDL_ThreadID()) {
+ _this->SendWakeupEvent(_this, _this->wakeup_window);
+ }
+ if (_this->wakeup_lock) {
+ SDL_UnlockMutex(_this->wakeup_lock);
+ }
+ }
+ return 0;
+}
+
/* Lock the event queue, take a peep at it, and unlock it */
int
SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
@@ -662,6 +680,11 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
} else {
return SDL_SetError("Couldn't lock event queue");
}
+
+ if (used > 0 && action == SDL_ADDEVENT) {
+ SDL_SendWakeupEvent();
+ }
+
return (used);
}
@@ -883,24 +906,6 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
}
}
-static int
-SDL_SendWakeupEvent()
-{
- SDL_VideoDevice *_this = SDL_GetVideoDevice();
- if (!_this || !_this->SendWakeupEvent) {
- return 0;
- }
- if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
- if (_this->wakeup_window && _this->blocking_thread_id != 0 && _this->blocking_thread_id != SDL_ThreadID()) {
- _this->SendWakeupEvent(_this, _this->wakeup_window);
- }
- if (_this->wakeup_lock) {
- SDL_UnlockMutex(_this->wakeup_lock);
- }
- }
- return 0;
-}
-
int
SDL_PushEvent(SDL_Event * event)
{
@@ -950,7 +955,6 @@ SDL_PushEvent(SDL_Event * event)
return -1;
}
- SDL_SendWakeupEvent();
SDL_GestureProcessEvent(event);
return 1;