diff --git a/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp b/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp index 6851b5982e..0e596876e0 100644 --- a/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp +++ b/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp @@ -1051,7 +1051,7 @@ public: CoreAudioIODevice& owner; int bitDepth = 32; - int xruns = 0; + std::atomic xruns = 0; Array sampleRates; Array bufferSizes; AudioDeviceID deviceID; @@ -1159,7 +1159,7 @@ private: return x.mSelector == kAudioDeviceProcessorOverload; }); - intern.xruns += xruns; + intern.xruns += (int) xruns; const auto detailsChanged = std::any_of (pa, pa + numAddresses, [] (const AudioObjectPropertyAddress& x) { @@ -1325,6 +1325,8 @@ public: void start (AudioIODeviceCallback* callback) override { + const ScopedLock sl (startStopLock); + if (internal->start (callback)) pendingCallback = nullptr; } @@ -1332,12 +1334,14 @@ public: void stop() override { stopAndGetLastCallback(); + + const ScopedLock sl (startStopLock); pendingCallback = nullptr; } void stopWithPendingCallback() { - const ScopedLock sl (closeLock); + const ScopedLock sl (startStopLock); if (pendingCallback == nullptr) pendingCallback = stopAndGetLastCallback(); @@ -1399,7 +1403,7 @@ private: AudioIODeviceCallback* pendingCallback = nullptr; AsyncRestarter* restarter = nullptr; BigInteger inputChannelsRequested, outputChannelsRequested; - CriticalSection closeLock; + CriticalSection startStopLock; AudioIODeviceCallback* stopAndGetLastCallback() const { @@ -1424,6 +1428,7 @@ private: getCurrentSampleRate(), getCurrentBufferSizeSamples()); + const ScopedLock sl { startStopLock }; start (pendingCallback); }