From a27986c31167d8ce60efcee7e901da241f63ed08 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 4 Aug 2021 15:28:33 -0300 Subject: Make audio disposal thread safe on all 3 backends (#2527) * Make audio disposal thread safe on all 3 backends * Make OpenAL more consistent with the other backends * Remove Window.Cursor = null, and change dummy TValue to byte --- .../SDL2HardwareDeviceDriver.cs | 33 ++++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs') diff --git a/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs b/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs index 07131d1d..2c1baa47 100644 --- a/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs +++ b/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs @@ -1,10 +1,9 @@ -using Ryujinx.Audio.Backends.Common; -using Ryujinx.Audio.Common; +using Ryujinx.Audio.Common; using Ryujinx.Audio.Integration; using Ryujinx.Memory; using Ryujinx.SDL2.Common; using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Runtime.InteropServices; using System.Threading; @@ -15,15 +14,13 @@ namespace Ryujinx.Audio.Backends.SDL2 { public class SDL2HardwareDeviceDriver : IHardwareDeviceDriver { - private object _lock = new object(); - - private ManualResetEvent _updateRequiredEvent; - private List _sessions; + private readonly ManualResetEvent _updateRequiredEvent; + private readonly ConcurrentDictionary _sessions; public SDL2HardwareDeviceDriver() { _updateRequiredEvent = new ManualResetEvent(false); - _sessions = new List(); + _sessions = new ConcurrentDictionary(); SDL2Driver.Instance.Initialize(); } @@ -64,22 +61,16 @@ namespace Ryujinx.Audio.Backends.SDL2 throw new NotImplementedException("Input direction is currently not implemented on SDL2 backend!"); } - lock (_lock) - { - SDL2HardwareDeviceSession session = new SDL2HardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount); + SDL2HardwareDeviceSession session = new SDL2HardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount); - _sessions.Add(session); + _sessions.TryAdd(session, 0); - return session; - } + return session; } - internal void Unregister(SDL2HardwareDeviceSession session) + internal bool Unregister(SDL2HardwareDeviceSession session) { - lock (_lock) - { - _sessions.Remove(session); - } + return _sessions.TryRemove(session, out _); } private static SDL_AudioSpec GetSDL2Spec(SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, uint sampleCount) @@ -149,10 +140,8 @@ namespace Ryujinx.Audio.Backends.SDL2 { if (disposing) { - while (_sessions.Count > 0) + foreach (SDL2HardwareDeviceSession session in _sessions.Keys) { - SDL2HardwareDeviceSession session = _sessions[_sessions.Count - 1]; - session.Dispose(); } -- cgit v1.2.3