aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Audio
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Audio')
-rw-r--r--Ryujinx.Audio/Input/AudioInputManager.cs25
-rw-r--r--Ryujinx.Audio/Input/AudioInputSystem.cs13
-rw-r--r--Ryujinx.Audio/Output/AudioOutputManager.cs25
-rw-r--r--Ryujinx.Audio/Output/AudioOutputSystem.cs11
-rw-r--r--Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs7
-rw-r--r--Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs10
6 files changed, 82 insertions, 9 deletions
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
{
@@ -62,6 +64,11 @@ namespace Ryujinx.Audio.Input
private int _activeSessionCount;
/// <summary>
+ /// The dispose state.
+ /// </summary>
+ private int _disposeState;
+
+ /// <summary>
/// Create a new <see cref="AudioInputManager"/>.
/// </summary>
public AudioInputManager()
@@ -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,11 +63,16 @@ namespace Ryujinx.Audio.Input
private AudioInputManager _manager;
/// <summary>
- /// THe lock of the parent.
+ /// The lock of the parent.
/// </summary>
private object _parentLock;
/// <summary>
+ /// The dispose state.
+ /// </summary>
+ private int _disposeState;
+
+ /// <summary>
/// Create a new <see cref="AudioInputSystem"/>.
/// </summary>
/// <param name="manager">The manager instance</param>
@@ -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)
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();
+ }
}
}
}
diff --git a/Ryujinx.Audio/Output/AudioOutputSystem.cs b/Ryujinx.Audio/Output/AudioOutputSystem.cs
index f5db9d7a..d32d417a 100644
--- a/Ryujinx.Audio/Output/AudioOutputSystem.cs
+++ b/Ryujinx.Audio/Output/AudioOutputSystem.cs
@@ -18,6 +18,7 @@
using Ryujinx.Audio.Common;
using Ryujinx.Audio.Integration;
using System;
+using System.Threading;
namespace Ryujinx.Audio.Output
{
@@ -67,6 +68,11 @@ namespace Ryujinx.Audio.Output
private object _parentLock;
/// <summary>
+ /// The dispose state.
+ /// </summary>
+ private int _disposeState;
+
+ /// <summary>
/// Create a new <see cref="AudioOutputSystem"/>.
/// </summary>
/// <param name="manager">The manager instance</param>
@@ -357,7 +363,10 @@ 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)
diff --git a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
index 943a2d78..6aed3c5d 100644
--- a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
+++ b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
@@ -94,6 +94,8 @@ namespace Ryujinx.Audio.Renderer.Server
private AudioRendererManager _manager;
+ private int _disposeState;
+
public AudioRenderSystem(AudioRendererManager manager, IWritableEvent systemEvent)
{
_manager = manager;
@@ -811,7 +813,10 @@ namespace Ryujinx.Audio.Renderer.Server
public void Dispose()
{
- Dispose(true);
+ if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0)
+ {
+ Dispose(true);
+ }
}
protected virtual void Dispose(bool disposing)
diff --git a/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs b/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs
index 004ac656..71d0f318 100644
--- a/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs
+++ b/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs
@@ -83,6 +83,11 @@ namespace Ryujinx.Audio.Renderer.Server
public AudioProcessor Processor { get; }
/// <summary>
+ /// The dispose state.
+ /// </summary>
+ private int _disposeState;
+
+ /// <summary>
/// Create a new <see cref="AudioRendererManager"/>.
/// </summary>
public AudioRendererManager()
@@ -313,7 +318,10 @@ namespace Ryujinx.Audio.Renderer.Server
public void Dispose()
{
- Dispose(true);
+ if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0)
+ {
+ Dispose(true);
+ }
}
protected virtual void Dispose(bool disposing)