Background audio device refreshing

In our application we build a list of all audio devices and all associated audio channels on a background thread. If we would do this on the main thread it would block the UI updates for too long, which we found out early on.

Unfortunately the audio backends schedule updates on the main thread themselves (using AsyncUpdater). This introduces a race condition between the background thread and the main thread (in scanForDevices()).

We would really like to have a way of controlling the device list change notification so we can schedule a refresh (call to scanForDevices) from our background thread ourselves.

Take for example CoreAudioIODeviceType. When the audio devices changes it calls triggerAsyncUpdate() which makes the main thread call handleAsyncUpdate() which calls audioDeviceListChanged():

void audioDeviceListChanged()
{
    scanForDevices();
    callDeviceChangeListeners();
}

If we would be able to disable the call to scanForDevices() the problem would be solved and we would be fully safe refreshing the devices on the background thread:

void audioDeviceListChanged()
{
    if (!disableCallingScanForDevicesWhenDeviceListChanges)
        scanForDevices();
    callDeviceChangeListeners();
}