From 00ce9eea620652b97b4d3e8cd9218c6fccff8b1c Mon Sep 17 00:00:00 2001 From: Mary Date: Tue, 29 Jun 2021 19:37:13 +0200 Subject: Fix disposing of IPC sessions server at emulation stop (#2334) --- Ryujinx.Audio/Input/AudioInputManager.cs | 25 +++++++++++++++++++++++-- Ryujinx.Audio/Input/AudioInputSystem.cs | 13 +++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'Ryujinx.Audio/Input') diff --git a/Ryujinx.Audio/Input/AudioInputManager.cs b/Ryujinx.Audio/Input/AudioInputManager.cs index e098ae9e..5c1f01db 100644 --- a/Ryujinx.Audio/Input/AudioInputManager.cs +++ b/Ryujinx.Audio/Input/AudioInputManager.cs @@ -21,6 +21,8 @@ using Ryujinx.Common.Logging; using Ryujinx.Memory; using System; using System.Diagnostics; +using System.Linq; +using System.Threading; namespace Ryujinx.Audio.Input { @@ -61,6 +63,11 @@ namespace Ryujinx.Audio.Input /// private int _activeSessionCount; + /// + /// The dispose state. + /// + private int _disposeState; + /// /// Create a new . /// @@ -248,14 +255,28 @@ namespace Ryujinx.Audio.Input public void Dispose() { - Dispose(true); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) + { + Dispose(true); + } } protected virtual void Dispose(bool disposing) { if (disposing) { - // Nothing to do here. + // Clone the sessions array to dispose them outside the lock. + AudioInputSystem[] sessions; + + lock (_sessionLock) + { + sessions = _sessions.ToArray(); + } + + foreach (AudioInputSystem input in sessions) + { + input?.Dispose(); + } } } } diff --git a/Ryujinx.Audio/Input/AudioInputSystem.cs b/Ryujinx.Audio/Input/AudioInputSystem.cs index 8064a947..b3fd91e7 100644 --- a/Ryujinx.Audio/Input/AudioInputSystem.cs +++ b/Ryujinx.Audio/Input/AudioInputSystem.cs @@ -18,6 +18,7 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Integration; using System; +using System.Threading; namespace Ryujinx.Audio.Input { @@ -62,10 +63,15 @@ namespace Ryujinx.Audio.Input private AudioInputManager _manager; /// - /// THe lock of the parent. + /// The lock of the parent. /// private object _parentLock; + /// + /// The dispose state. + /// + private int _disposeState; + /// /// Create a new . /// @@ -384,7 +390,10 @@ namespace Ryujinx.Audio.Input public void Dispose() { - Dispose(true); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) + { + Dispose(true); + } } protected virtual void Dispose(bool disposing) -- cgit v1.2.3