mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-16 23:06:03 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user