SDL: Move special sentinel handling inside SDL_PeepEvents()

From 954858846d2883864b4e5fef55f31bb92f1514cc Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 6 Jan 2022 13:58:39 -0800
Subject: [PATCH] Move special sentinel handling inside SDL_PeepEvents()

---
 src/events/SDL_events.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index f5ead49a3b7..4459896e550 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -721,9 +721,14 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
                             SDL_CutEvent(entry);
                         }
                     }
-                    if (type != SDL_POLLSENTINEL || include_sentinel) {
-                        ++used;
+                    if (type == SDL_POLLSENTINEL) {
+                        /* Special handling for the sentinel event */
+                        if (!include_sentinel || SDL_AtomicGet(&SDL_sentinel_pending) > 0) {
+                            /* Skip it, we don't want to include it or there's another one pending */
+                            continue;
+                        }
                     }
+                    ++used;
                 }
             }
         }
@@ -983,7 +988,6 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
     }
 
     /* First check for existing events */
-retry:
     switch (SDL_PeepEventsInternal(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT, include_sentinel)) {
     case -1:
         return 0;
@@ -996,10 +1000,6 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
     default:
         if (event && event->type == SDL_POLLSENTINEL) {
             /* Reached the end of a poll cycle, and not willing to wait */
-            if (SDL_AtomicGet(&SDL_sentinel_pending) > 0) {
-                /* We have another sentinel pending, skip this and keep going */
-                goto retry;
-            }
             return 0;
         }
         /* Has existing events */