@@ -738,21 +738,17 @@ static void SDL_CutEvent(SDL_EventEntry *entry)
738
738
739
739
static int SDL_SendWakeupEvent (void )
740
740
{
741
+ SDL_Window * wakeup_window ;
741
742
SDL_VideoDevice * _this = SDL_GetVideoDevice ();
742
743
if (_this == NULL || !_this -> SendWakeupEvent ) {
743
744
return 0 ;
744
745
}
745
746
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 );
754
751
}
755
- SDL_UnlockMutex (_this -> wakeup_lock );
756
752
757
753
return 0 ;
758
754
}
@@ -1009,18 +1005,7 @@ static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Eve
1009
1005
int status ;
1010
1006
SDL_PumpEventsInternal (SDL_TRUE );
1011
1007
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 );
1024
1009
if (status < 0 ) {
1025
1010
/* Got an error: return */
1026
1011
break ;
@@ -1033,8 +1018,6 @@ static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Eve
1033
1018
if (timeout > 0 ) {
1034
1019
Uint32 elapsed = SDL_GetTicks () - start ;
1035
1020
if (elapsed >= (Uint32 )timeout ) {
1036
- /* Set wakeup_window to NULL without holding the lock. */
1037
- _this -> wakeup_window = NULL ;
1038
1021
return 0 ;
1039
1022
}
1040
1023
loop_timeout = (int )((Uint32 )timeout - elapsed );
@@ -1049,9 +1032,9 @@ static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Eve
1049
1032
}
1050
1033
}
1051
1034
1035
+ SDL_AtomicSetPtr (& _this -> wakeup_window , wakeup_window );
1052
1036
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 );
1055
1038
if (status == 0 && poll_interval != SDL_MAX_SINT16 && loop_timeout == poll_interval ) {
1056
1039
/* We may have woken up to poll. Try again */
1057
1040
continue ;
0 commit comments