From 938886824e7e53aac287958a8a175ee36d028e2a Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Tue, 3 Dec 2024 12:00:40 -0300 Subject: [PATCH] more Lock --- src/Ryujinx.Audio/Input/AudioInputManager.cs | 2 +- src/Ryujinx.Audio/Output/AudioOutputManager.cs | 2 +- .../Renderer/Server/AudioRendererManager.cs | 4 ++-- .../Multithreading/ThreadedRenderer.cs | 2 +- .../SoftwareKeyboard/SoftwareKeyboardRendererBase.cs | 3 ++- src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs | 4 ++-- src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs | 2 +- .../SystemAppletProxy/ISelfController.cs | 3 ++- .../LdnMitm/Proxy/LdnProxyUdpServer.cs | 2 +- .../NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs | 2 +- src/Ryujinx.HLE/PerformanceStatistics.cs | 12 +++++------- .../Sdk/Sf/Cmif/ServerDomainManager.cs | 4 ++-- src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs | 4 ++-- src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs | 8 +++----- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 3 ++- src/Ryujinx.Input.SDL2/SDL2Keyboard.cs | 3 ++- src/Ryujinx.Memory/SparseMemoryBlock.cs | 2 +- src/Ryujinx.Memory/Tracking/RegionHandle.cs | 2 +- src/Ryujinx/Input/AvaloniaKeyboard.cs | 3 ++- 19 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Ryujinx.Audio/Input/AudioInputManager.cs b/src/Ryujinx.Audio/Input/AudioInputManager.cs index 4f948673c..ffc3e6da2 100644 --- a/src/Ryujinx.Audio/Input/AudioInputManager.cs +++ b/src/Ryujinx.Audio/Input/AudioInputManager.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Audio.Input /// /// Lock used for session allocation. /// - private readonly object _sessionLock = new(); + private readonly Lock _sessionLock = new(); /// /// The session ids allocation table. diff --git a/src/Ryujinx.Audio/Output/AudioOutputManager.cs b/src/Ryujinx.Audio/Output/AudioOutputManager.cs index 4ba3fa111..13e169a24 100644 --- a/src/Ryujinx.Audio/Output/AudioOutputManager.cs +++ b/src/Ryujinx.Audio/Output/AudioOutputManager.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Audio.Output /// /// Lock used for session allocation. /// - private readonly object _sessionLock = new(); + private readonly Lock _sessionLock = new(); /// /// The session ids allocation table. diff --git a/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs b/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs index e334a89f6..6d7db059f 100644 --- a/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs +++ b/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs @@ -19,12 +19,12 @@ namespace Ryujinx.Audio.Renderer.Server /// /// Lock used for session allocation. /// - private readonly object _sessionLock = new(); + private readonly Lock _sessionLock = new(); /// /// Lock used to control the running state. /// - private readonly object _audioProcessorLock = new(); + private readonly Lock _audioProcessorLock = new(); /// /// The session ids allocation table. diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs index 0bd3dc592..6375d290c 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs @@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading public uint ProgramCount { get; set; } = 0; private Action _interruptAction; - private readonly object _interruptLock = new(); + private readonly Lock _interruptLock = new(); public event EventHandler ScreenCaptured; diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs index 67b5f2b1f..e17b36911 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using System.Threading; namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { @@ -21,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard const string CancelText = "Cancel"; const string ControllerToggleText = "Toggle input"; - private readonly object _bufferLock = new(); + private readonly Lock _bufferLock = new(); private RenderingSurfaceInfo _surfaceInfo = null; private SKImageInfo _imageInfo; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs index 422f03c64..b4aa5ca5c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs @@ -40,8 +40,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public ProcessState State { get; private set; } - private readonly object _processLock = new(); - private readonly object _threadingLock = new(); + private readonly Lock _processLock = new(); + private readonly Lock _threadingLock = new(); public KAddressArbiter AddressArbiter { get; private set; } diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs index 835bf5d40..4abc0ddf3 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs @@ -112,7 +112,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading public bool WaitingInArbitration { get; set; } - private readonly object _activityOperationLock = new(); + private readonly Lock _activityOperationLock = new(); public KThread(KernelContext context) : base(context) { diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs index 85898f138..8e0f515ba 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs @@ -4,6 +4,7 @@ using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy.Types; using Ryujinx.Horizon.Common; using System; +using System.Threading; namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy { @@ -17,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys private KEvent _accumulatedSuspendedTickChangedEvent; private int _accumulatedSuspendedTickChangedEventHandle; - private readonly object _fatalSectionLock = new(); + private readonly Lock _fatalSectionLock = new(); private int _fatalSectionCount; // TODO: Set this when the game goes in suspension (go back to home menu ect), we currently don't support that so we can keep it set to 0. diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnMitm/Proxy/LdnProxyUdpServer.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnMitm/Proxy/LdnProxyUdpServer.cs index 0f5875a1d..536ae476d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnMitm/Proxy/LdnProxyUdpServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnMitm/Proxy/LdnProxyUdpServer.cs @@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm.Proxy private byte[] _buffer; private int _bufferEnd; - private readonly object _scanLock = new(); + private readonly Lock _scanLock = new(); private Dictionary _scanResultsLast = new(); private Dictionary _scanResults = new(); diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs index b83c642e5..49637f757 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs @@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl private readonly Switch _device; - private readonly object _syncpointAllocatorLock = new(); + private readonly Lock _syncpointAllocatorLock = new(); public NvHostSyncpt(Switch device) { diff --git a/src/Ryujinx.HLE/PerformanceStatistics.cs b/src/Ryujinx.HLE/PerformanceStatistics.cs index 3767a7fb4..9de0cdff2 100644 --- a/src/Ryujinx.HLE/PerformanceStatistics.cs +++ b/src/Ryujinx.HLE/PerformanceStatistics.cs @@ -1,4 +1,5 @@ using Ryujinx.Common; +using System.Threading; using System.Timers; namespace Ryujinx.HLE @@ -20,12 +21,12 @@ namespace Ryujinx.HLE private readonly long[] _framesRendered; private readonly double[] _percentTime; - private readonly object[] _frameLock; - private readonly object[] _percentLock; + private readonly Lock[] _frameLock = new[] { new Lock() }; + private readonly Lock[] _percentLock = new[] { new Lock() }; private readonly double _ticksToSeconds; - private readonly Timer _resetTimer; + private readonly System.Timers.Timer _resetTimer; public PerformanceStatistics() { @@ -41,10 +42,7 @@ namespace Ryujinx.HLE _framesRendered = new long[1]; _percentTime = new double[1]; - _frameLock = new[] { new object() }; - _percentLock = new[] { new object() }; - - _resetTimer = new Timer(750); + _resetTimer = new(750); _resetTimer.Elapsed += ResetTimerElapsed; _resetTimer.AutoReset = true; diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs index 7762345af..13f9fb7a9 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs @@ -1,6 +1,7 @@ using Ryujinx.Horizon.Common; using System; using System.Collections.Generic; +using System.Threading; namespace Ryujinx.Horizon.Sdk.Sf.Cmif { @@ -209,14 +210,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif } private readonly EntryManager _entryManager; - private readonly object _entryOwnerLock; + private readonly Lock _entryOwnerLock = new(); private readonly HashSet _domains; private readonly int _maxDomains; public ServerDomainManager(int entryCount, int maxDomains) { _entryManager = new EntryManager(entryCount); - _entryOwnerLock = new object(); _domains = new HashSet(); _maxDomains = maxDomains; } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs index e8957b758..6aa32faee 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs @@ -4,6 +4,7 @@ using Ryujinx.Horizon.Sdk.Sm; using System; using System.Collections.Generic; using System.Numerics; +using System.Threading; namespace Ryujinx.Horizon.Sdk.Sf.Hipc { @@ -17,7 +18,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc private readonly ulong _pointerBuffersBaseAddress; private readonly ulong _savedMessagesBaseAddress; - private readonly object _resourceLock; + private readonly Lock _resourceLock = new(); private readonly ulong[] _sessionAllocationBitmap; private readonly HashSet _sessions; private readonly HashSet _servers; @@ -42,7 +43,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc } } - _resourceLock = new object(); _sessionAllocationBitmap = new ulong[(maxSessions + 63) / 64]; _sessions = new HashSet(); _servers = new HashSet(); diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs index 570e3c802..31ca264e3 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs @@ -4,6 +4,7 @@ using Ryujinx.Horizon.Sdk.Sf.Cmif; using Ryujinx.Horizon.Sdk.Sm; using System; using System.Linq; +using System.Threading; namespace Ryujinx.Horizon.Sdk.Sf.Hipc { @@ -16,8 +17,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc private readonly MultiWait _multiWait; private readonly MultiWait _waitList; - private readonly object _multiWaitSelectionLock; - private readonly object _waitListLock; + private readonly Lock _multiWaitSelectionLock = new(); + private readonly Lock _waitListLock = new(); private readonly Event _requestStopEvent; private readonly Event _notifyEvent; @@ -39,9 +40,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc _multiWait = new MultiWait(); _waitList = new MultiWait(); - _multiWaitSelectionLock = new object(); - _waitListLock = new object(); - _requestStopEvent = new Event(EventClearMode.ManualClear); _notifyEvent = new Event(EventClearMode.ManualClear); diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index af6f4c625..12bfab4bb 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -4,6 +4,7 @@ using Ryujinx.Common.Logging; using System; using System.Collections.Generic; using System.Numerics; +using System.Threading; using static SDL2.SDL; namespace Ryujinx.Input.SDL2 @@ -58,7 +59,7 @@ namespace Ryujinx.Input.SDL2 SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_INVALID, }; - private readonly object _userMappingLock = new(); + private readonly Lock _userMappingLock = new(); private readonly List _buttonsUserMapping; diff --git a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs index a0dd8ab95..8d6a30d11 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; +using System.Threading; using static SDL2.SDL; using ConfigKey = Ryujinx.Common.Configuration.Hid.Key; @@ -17,7 +18,7 @@ namespace Ryujinx.Input.SDL2 public bool IsValid => To is not GamepadButtonInputId.Unbound && From is not Key.Unbound; } - private readonly object _userMappingLock = new(); + private readonly Lock _userMappingLock = new(); #pragma warning disable IDE0052 // Remove unread private member private readonly SDL2KeyboardDriver _driver; diff --git a/src/Ryujinx.Memory/SparseMemoryBlock.cs b/src/Ryujinx.Memory/SparseMemoryBlock.cs index 523685de1..5717d7b64 100644 --- a/src/Ryujinx.Memory/SparseMemoryBlock.cs +++ b/src/Ryujinx.Memory/SparseMemoryBlock.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Memory private readonly PageInitDelegate _pageInit; - private readonly object _lock = new object(); + private readonly Lock _lock = new(); private readonly ulong _pageSize; private readonly MemoryBlock _reservedBlock; private readonly List _mappedBlocks; diff --git a/src/Ryujinx.Memory/Tracking/RegionHandle.cs b/src/Ryujinx.Memory/Tracking/RegionHandle.cs index a94ffa43c..4e81a9723 100644 --- a/src/Ryujinx.Memory/Tracking/RegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/RegionHandle.cs @@ -51,7 +51,7 @@ namespace Ryujinx.Memory.Tracking private event Action OnDirty; - private readonly object _preActionLock = new(); + private readonly Lock _preActionLock = new(); private RegionSignal _preAction; // Action to perform before a read or write. This will block the memory access. private PreciseRegionSignal _preciseAction; // Action to perform on a precise read or write. private readonly List _regions; diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs index 95d2936f6..0b63af2d9 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboard.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboard.cs @@ -4,6 +4,7 @@ using Ryujinx.Input; using System; using System.Collections.Generic; using System.Numerics; +using System.Threading; using ConfigKey = Ryujinx.Common.Configuration.Hid.Key; using Key = Ryujinx.Input.Key; @@ -15,7 +16,7 @@ namespace Ryujinx.Ava.Input private readonly AvaloniaKeyboardDriver _driver; private StandardKeyboardInputConfig _configuration; - private readonly object _userMappingLock = new(); + private readonly Lock _userMappingLock = new(); public string Id { get; } public string Name { get; }