diff options
author | Mary <me@thog.eu> | 2021-06-29 19:37:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 19:37:13 +0200 |
commit | 00ce9eea620652b97b4d3e8cd9218c6fccff8b1c (patch) | |
tree | f488b1b378a8ecbeaf54d5a7916062784a5588dc /Ryujinx.Audio/Output/AudioOutputManager.cs | |
parent | fbb4019ed5c12c4a888c7b09db648ac595366896 (diff) |
Fix disposing of IPC sessions server at emulation stop (#2334)
Diffstat (limited to 'Ryujinx.Audio/Output/AudioOutputManager.cs')
-rw-r--r-- | Ryujinx.Audio/Output/AudioOutputManager.cs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Ryujinx.Audio/Output/AudioOutputManager.cs b/Ryujinx.Audio/Output/AudioOutputManager.cs index baa84997..852632fa 100644 --- a/Ryujinx.Audio/Output/AudioOutputManager.cs +++ b/Ryujinx.Audio/Output/AudioOutputManager.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.Output { @@ -62,6 +64,11 @@ namespace Ryujinx.Audio.Output private int _activeSessionCount; /// <summary> + /// The dispose state. + /// </summary> + private int _disposeState; + + /// <summary> /// Create a new <see cref="AudioOutputManager"/>. /// </summary> public AudioOutputManager() @@ -242,14 +249,28 @@ namespace Ryujinx.Audio.Output 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. + AudioOutputSystem[] sessions; + + lock (_sessionLock) + { + sessions = _sessions.ToArray(); + } + + foreach (AudioOutputSystem output in sessions) + { + output?.Dispose(); + } } } } |