Android: use Mutex instead of Semphore for bug 4142

This commit is contained in:
Sylvain Becker
2019-01-03 20:18:29 +01:00
parent 23478642bd
commit 2e19343df6
5 changed files with 33 additions and 31 deletions

View File

@@ -80,9 +80,9 @@ Android_PumpEvents(_THIS)
#if SDL_ANDROID_BLOCK_ON_PAUSE
if (isPaused && !isPausing) {
/* Make sure this is the last thing we do before pausing */
SDL_SemWait(Android_ActivitySem);
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_SemPost(Android_ActivitySem);
SDL_UnlockMutex(Android_ActivityMutex);
ANDROIDAUDIO_PauseDevices();
if (SDL_SemWait(Android_ResumeSem) == 0) {
@@ -94,9 +94,9 @@ Android_PumpEvents(_THIS)
ANDROIDAUDIO_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!SDL_HasEvent(SDL_QUIT)) {
SDL_SemWait(Android_ActivitySem);
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_restore(Android_Window);
SDL_SemPost(Android_ActivitySem);
SDL_UnlockMutex(Android_ActivityMutex);
}
}
}
@@ -115,9 +115,9 @@ Android_PumpEvents(_THIS)
}
#else
if (SDL_SemTryWait(Android_PauseSem) == 0) {
SDL_SemWait(Android_ActivitySem);
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_SemPost(Android_ActivitySem);
SDL_UnlockMutex(Android_ActivityMutex);
ANDROIDAUDIO_PauseDevices();
isPaused = 1;

View File

@@ -66,7 +66,8 @@ int Android_DeviceHeight = 0;
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
static int Android_ScreenRate = 0;
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL, *Android_ActivitySem = NULL;
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = NULL;
static int
Android_Available(void)

View File

@@ -41,7 +41,8 @@ extern int Android_SurfaceWidth;
extern int Android_SurfaceHeight;
extern int Android_DeviceWidth;
extern int Android_DeviceHeight;
extern SDL_sem *Android_PauseSem, *Android_ResumeSem, *Android_ActivitySem;
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
extern SDL_mutex *Android_ActivityMutex;
#endif /* SDL_androidvideo_h_ */

View File

@@ -42,7 +42,7 @@ Android_CreateWindow(_THIS, SDL_Window * window)
SDL_WindowData *data;
int retval = 0;
SDL_SemWait(Android_ActivitySem);
SDL_LockMutex(Android_ActivityMutex);
if (Android_Window) {
retval = SDL_SetError("Android only supports one window");
@@ -102,7 +102,7 @@ Android_CreateWindow(_THIS, SDL_Window * window)
endfunction:
SDL_SemPost(Android_ActivitySem);
SDL_UnlockMutex(Android_ActivityMutex);
return retval;
}
@@ -151,7 +151,7 @@ Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display
void
Android_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_SemWait(Android_ActivitySem);
SDL_LockMutex(Android_ActivityMutex);
if (window == Android_Window) {
Android_Window = NULL;
@@ -173,7 +173,7 @@ Android_DestroyWindow(_THIS, SDL_Window *window)
}
}
SDL_SemPost(Android_ActivitySem);
SDL_UnlockMutex(Android_ActivityMutex);
}
SDL_bool