audio: Fixed race condition in subsystem shutdown.

This makes sure new devices can't be created when we're in the process of
shutting down.
main
Ryan C. Gordon 2023-09-20 10:00:44 -04:00
parent 23f60203a3
commit 0dc0434a3e
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 4 additions and 1 deletions

View File

@ -246,7 +246,10 @@ static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, SDL_bool isc
{
SDL_assert(name != NULL);
if (SDL_AtomicGet(&current_audio.shutting_down)) {
SDL_LockRWLockForReading(current_audio.device_list_lock);
const int shutting_down = SDL_AtomicGet(&current_audio.shutting_down);
SDL_UnlockRWLock(current_audio.device_list_lock);
if (shutting_down) {
return NULL; // we're shutting down, don't add any devices that are hotplugged at the last possible moment.
}