audio: backends now "find" instead of "obtain" devices by handle.

Every single case of this didn't want the device locked, so just looking
it up without having to immediately unlock it afterwards is better here.

Often these devices are passed on to other functions that want to lock them
themselves anyhow (disconnects, default changes, etc).
This commit is contained in:
Ryan C. Gordon
2023-07-11 13:59:54 -04:00
parent c3f5a5fc72
commit 2fb122fe46
6 changed files with 16 additions and 46 deletions

View File

@@ -988,7 +988,7 @@ static SDL_AudioDevice *ObtainPhysicalAudioDevice(SDL_AudioDeviceID devid)
return dev;
}
SDL_AudioDevice *SDL_ObtainPhysicalAudioDeviceByHandle(void *handle)
SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle)
{
if (!SDL_GetCurrentAudioDriver()) {
SDL_SetError("Audio subsystem is not initialized");
@@ -1000,8 +1000,6 @@ SDL_AudioDevice *SDL_ObtainPhysicalAudioDeviceByHandle(void *handle)
SDL_AudioDevice *dev = NULL;
for (dev = current_audio.output_devices; dev != NULL; dev = dev->next) {
if (dev->handle == handle) { // found it?
SDL_LockMutex(dev->lock); // caller must unlock.
SDL_assert(!SDL_AtomicGet(&dev->condemned)); // shouldn't be in the list if pending deletion.
break;
}
}
@@ -1010,8 +1008,6 @@ SDL_AudioDevice *SDL_ObtainPhysicalAudioDeviceByHandle(void *handle)
// !!! FIXME: code duplication, from above.
for (dev = current_audio.capture_devices; dev != NULL; dev = dev->next) {
if (dev->handle == handle) { // found it?
SDL_LockMutex(dev->lock); // caller must unlock.
SDL_assert(!SDL_AtomicGet(&dev->condemned)); // shouldn't be in the list if pending deletion.
break;
}
}
@@ -1023,6 +1019,8 @@ SDL_AudioDevice *SDL_ObtainPhysicalAudioDeviceByHandle(void *handle)
SDL_SetError("Device handle not found");
}
SDL_assert(!SDL_AtomicGet(&dev->condemned)); // shouldn't be in the list if pending deletion.
return dev;
}