From 00ce9eea620652b97b4d3e8cd9218c6fccff8b1c Mon Sep 17 00:00:00 2001
From: Mary <me@thog.eu>
Date: Tue, 29 Jun 2021 19:37:13 +0200
Subject: Fix disposing of IPC sessions server at emulation stop (#2334)

---
 Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs')

diff --git a/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs b/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs
index 925a1cb4..884e75ed 100644
--- a/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs
+++ b/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs
@@ -17,6 +17,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
         private DynamicRingBuffer _ringBuffer;
         private ulong _playedSampleCount;
         private ManualResetEvent _updateRequiredEvent;
+        private int _disposeState;
 
         public SoundIoHardwareDeviceSession(SoundIoHardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
         {
@@ -435,7 +436,10 @@ namespace Ryujinx.Audio.Backends.SoundIo
 
         public override void Dispose()
         {
-            Dispose(true);
+            if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0)
+            {
+                Dispose(true);
+            }
         }
     }
 }
-- 
cgit v1.2.3-70-g09d2