@@ -738,21 +738,17 @@ static void SDL_CutEvent(SDL_EventEntry *entry)
738738
739739static int SDL_SendWakeupEvent (void )
740740{
741+ SDL_Window * wakeup_window ;
741742 SDL_VideoDevice * _this = SDL_GetVideoDevice ();
742743 if (_this == NULL || !_this -> SendWakeupEvent ) {
743744 return 0 ;
744745 }
745746
746- SDL_LockMutex (_this -> wakeup_lock );
747- {
748- if (_this -> wakeup_window ) {
749- _this -> SendWakeupEvent (_this , _this -> wakeup_window );
750-
751- /* No more wakeup events needed until we enter a new wait */
752- _this -> wakeup_window = NULL ;
753- }
747+ /* We only want to do this once while waiting for an event, so set it to NULL atomically here */
748+ wakeup_window = (SDL_Window * )SDL_AtomicSetPtr (& _this -> wakeup_window , NULL );
749+ if (wakeup_window ) {
750+ _this -> SendWakeupEvent (_this , wakeup_window );
754751 }
755- SDL_UnlockMutex (_this -> wakeup_lock );
756752
757753 return 0 ;
758754}
@@ -1009,18 +1005,7 @@ static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Eve
10091005 int status ;
10101006 SDL_PumpEventsInternal (SDL_TRUE );
10111007
1012- SDL_LockMutex (_this -> wakeup_lock );
1013- {
1014- status = SDL_PeepEvents (event , 1 , SDL_GETEVENT , SDL_FIRSTEVENT , SDL_LASTEVENT );
1015- /* If status == 0 we are going to block so wakeup will be needed. */
1016- if (status == 0 ) {
1017- _this -> wakeup_window = wakeup_window ;
1018- } else {
1019- _this -> wakeup_window = NULL ;
1020- }
1021- }
1022- SDL_UnlockMutex (_this -> wakeup_lock );
1023-
1008+ status = SDL_PeepEvents (event , 1 , SDL_GETEVENT , SDL_FIRSTEVENT , SDL_LASTEVENT );
10241009 if (status < 0 ) {
10251010 /* Got an error: return */
10261011 break ;
@@ -1033,8 +1018,6 @@ static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Eve
10331018 if (timeout > 0 ) {
10341019 Uint32 elapsed = SDL_GetTicks () - start ;
10351020 if (elapsed >= (Uint32 )timeout ) {
1036- /* Set wakeup_window to NULL without holding the lock. */
1037- _this -> wakeup_window = NULL ;
10381021 return 0 ;
10391022 }
10401023 loop_timeout = (int )((Uint32 )timeout - elapsed );
@@ -1049,9 +1032,9 @@ static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Eve
10491032 }
10501033 }
10511034
1035+ SDL_AtomicSetPtr (& _this -> wakeup_window , wakeup_window );
10521036 status = _this -> WaitEventTimeout (_this , loop_timeout );
1053- /* Set wakeup_window to NULL without holding the lock. */
1054- _this -> wakeup_window = NULL ;
1037+ SDL_AtomicSetPtr (& _this -> wakeup_window , NULL );
10551038 if (status == 0 && poll_interval != SDL_MAX_SINT16 && loop_timeout == poll_interval ) {
10561039 /* We may have woken up to poll. Try again */
10571040 continue ;
0 commit comments