diff --git a/Directory.Packages.props b/Directory.Packages.props index e6e2f14b80..2d23412913 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,6 +1,7 @@ true + preview diff --git a/src/ARMeilleure/Translation/Cache/JitCache.cs b/src/ARMeilleure/Translation/Cache/JitCache.cs index e2b5e2d106..7632711341 100644 --- a/src/ARMeilleure/Translation/Cache/JitCache.cs +++ b/src/ARMeilleure/Translation/Cache/JitCache.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; +using System.Threading; namespace ARMeilleure.Translation.Cache { @@ -26,7 +27,7 @@ namespace ARMeilleure.Translation.Cache private static readonly List _cacheEntries = new(); - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static bool _initialized; [SupportedOSPlatform("windows")] diff --git a/src/ARMeilleure/Translation/PTC/Ptc.cs b/src/ARMeilleure/Translation/PTC/Ptc.cs index c2eed7a552..e166430f85 100644 --- a/src/ARMeilleure/Translation/PTC/Ptc.cs +++ b/src/ARMeilleure/Translation/PTC/Ptc.cs @@ -57,7 +57,7 @@ namespace ARMeilleure.Translation.PTC private readonly ManualResetEvent _waitEvent; - private readonly object _lock; + private readonly Lock _lock; private bool _disposed; @@ -87,7 +87,7 @@ namespace ARMeilleure.Translation.PTC _waitEvent = new ManualResetEvent(true); - _lock = new object(); + _lock = new Lock(); _disposed = false; diff --git a/src/ARMeilleure/Translation/PTC/PtcProfiler.cs b/src/ARMeilleure/Translation/PTC/PtcProfiler.cs index 0fe78edab4..62c596d6e6 100644 --- a/src/ARMeilleure/Translation/PTC/PtcProfiler.cs +++ b/src/ARMeilleure/Translation/PTC/PtcProfiler.cs @@ -41,7 +41,7 @@ namespace ARMeilleure.Translation.PTC private readonly ManualResetEvent _waitEvent; - private readonly object _lock; + private readonly Lock _lock; private bool _disposed; @@ -65,7 +65,7 @@ namespace ARMeilleure.Translation.PTC _waitEvent = new ManualResetEvent(true); - _lock = new object(); + _lock = new Lock(); _disposed = false; diff --git a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs index 3b91291302..7292450a66 100644 --- a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs @@ -5,6 +5,7 @@ using Ryujinx.Memory; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading; namespace Ryujinx.Audio.Backends.OpenAL { @@ -18,7 +19,7 @@ namespace Ryujinx.Audio.Backends.OpenAL private ulong _playedSampleCount; private float _volume; - private readonly object _lock = new(); + private readonly Lock _lock = new(); public OpenALHardwareDeviceSession(OpenALHardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount) { diff --git a/src/Ryujinx.Audio/AudioManager.cs b/src/Ryujinx.Audio/AudioManager.cs index 370d3d0980..8c2c0ef6b1 100644 --- a/src/Ryujinx.Audio/AudioManager.cs +++ b/src/Ryujinx.Audio/AudioManager.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Audio /// /// Lock used to control the waiters registration. /// - private readonly object _lock = new(); + private readonly Lock _lock = new(); /// /// Events signaled when the driver played audio buffers. diff --git a/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs b/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs index 7aefe88654..6f31755a35 100644 --- a/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs +++ b/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs @@ -2,6 +2,7 @@ using Ryujinx.Common; using Ryujinx.Common.Memory; using System; using System.Buffers; +using System.Threading; namespace Ryujinx.Audio.Backends.Common { @@ -12,7 +13,7 @@ namespace Ryujinx.Audio.Backends.Common { private const int RingBufferAlignment = 2048; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private MemoryOwner _bufferOwner; private Memory _buffer; diff --git a/src/Ryujinx.Audio/Input/AudioInputManager.cs b/src/Ryujinx.Audio/Input/AudioInputManager.cs index d56997e9cd..ffc3e6da2f 100644 --- a/src/Ryujinx.Audio/Input/AudioInputManager.cs +++ b/src/Ryujinx.Audio/Input/AudioInputManager.cs @@ -14,12 +14,12 @@ namespace Ryujinx.Audio.Input /// public class AudioInputManager : IDisposable { - private readonly object _lock = new(); + private readonly Lock _lock = new(); /// /// 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/Input/AudioInputSystem.cs b/src/Ryujinx.Audio/Input/AudioInputSystem.cs index 34623b34fd..65b99745d7 100644 --- a/src/Ryujinx.Audio/Input/AudioInputSystem.cs +++ b/src/Ryujinx.Audio/Input/AudioInputSystem.cs @@ -48,7 +48,7 @@ namespace Ryujinx.Audio.Input /// /// The lock of the parent. /// - private readonly object _parentLock; + private readonly Lock _parentLock; /// /// The dispose state. @@ -62,7 +62,7 @@ namespace Ryujinx.Audio.Input /// The lock of the manager /// The hardware device session /// The buffer release event of the audio input - public AudioInputSystem(AudioInputManager manager, object parentLock, IHardwareDeviceSession deviceSession, IWritableEvent bufferEvent) + public AudioInputSystem(AudioInputManager manager, Lock parentLock, IHardwareDeviceSession deviceSession, IWritableEvent bufferEvent) { _manager = manager; _parentLock = parentLock; diff --git a/src/Ryujinx.Audio/Output/AudioOutputManager.cs b/src/Ryujinx.Audio/Output/AudioOutputManager.cs index 308cd1564e..13e169a24f 100644 --- a/src/Ryujinx.Audio/Output/AudioOutputManager.cs +++ b/src/Ryujinx.Audio/Output/AudioOutputManager.cs @@ -14,12 +14,12 @@ namespace Ryujinx.Audio.Output /// public class AudioOutputManager : IDisposable { - private readonly object _lock = new(); + private readonly Lock _lock = new(); /// /// 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/AudioOutputSystem.cs b/src/Ryujinx.Audio/Output/AudioOutputSystem.cs index f9b9bdcf1d..dc7d52cedf 100644 --- a/src/Ryujinx.Audio/Output/AudioOutputSystem.cs +++ b/src/Ryujinx.Audio/Output/AudioOutputSystem.cs @@ -48,7 +48,7 @@ namespace Ryujinx.Audio.Output /// /// THe lock of the parent. /// - private readonly object _parentLock; + private readonly Lock _parentLock; /// /// The dispose state. @@ -62,7 +62,7 @@ namespace Ryujinx.Audio.Output /// The lock of the manager /// The hardware device session /// The buffer release event of the audio output - public AudioOutputSystem(AudioOutputManager manager, object parentLock, IHardwareDeviceSession deviceSession, IWritableEvent bufferEvent) + public AudioOutputSystem(AudioOutputManager manager, Lock parentLock, IHardwareDeviceSession deviceSession, IWritableEvent bufferEvent) { _manager = manager; _parentLock = parentLock; diff --git a/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs b/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs index 246889c480..65a134af18 100644 --- a/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs +++ b/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs @@ -26,7 +26,7 @@ namespace Ryujinx.Audio.Renderer.Server { public class AudioRenderSystem : IDisposable { - private readonly object _lock = new(); + private readonly Lock _lock = new(); private AudioRendererRenderingDevice _renderingDevice; private AudioRendererExecutionMode _executionMode; diff --git a/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs b/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs index e334a89f65..6d7db059f0 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.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs index dbc2c9b3f7..8b3f394397 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Threading; namespace Ryujinx.Audio.Renderer.Server.Upsampler { @@ -16,7 +17,7 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler /// /// Global lock of the object. /// - private readonly object _lock = new(); + private readonly Lock _lock = new(); /// /// The upsamplers instances. diff --git a/src/Ryujinx.Common/PreciseSleep/NanosleepPool.cs b/src/Ryujinx.Common/PreciseSleep/NanosleepPool.cs index c0973dcb32..45b8e95fae 100644 --- a/src/Ryujinx.Common/PreciseSleep/NanosleepPool.cs +++ b/src/Ryujinx.Common/PreciseSleep/NanosleepPool.cs @@ -124,7 +124,7 @@ namespace Ryujinx.Common.PreciseSleep } } - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly List _threads = new(); private readonly List _active = new(); private readonly Stack _free = new(); diff --git a/src/Ryujinx.Common/PreciseSleep/WindowsGranularTimer.cs b/src/Ryujinx.Common/PreciseSleep/WindowsGranularTimer.cs index 3bf092704b..cef4dc9273 100644 --- a/src/Ryujinx.Common/PreciseSleep/WindowsGranularTimer.cs +++ b/src/Ryujinx.Common/PreciseSleep/WindowsGranularTimer.cs @@ -50,7 +50,7 @@ namespace Ryujinx.Common.SystemInterop private long _lastTicks = PerformanceCounter.ElapsedTicks; private long _lastId; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly List _waitingObjects = new(); private WindowsGranularTimer() diff --git a/src/Ryujinx.Cpu/AppleHv/HvVm.cs b/src/Ryujinx.Cpu/AppleHv/HvVm.cs index c4f107532e..93dc48ff67 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvVm.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvVm.cs @@ -1,6 +1,7 @@ using Ryujinx.Memory; using System; using System.Runtime.Versioning; +using System.Threading; namespace Ryujinx.Cpu.AppleHv { @@ -12,7 +13,7 @@ namespace Ryujinx.Cpu.AppleHv private static int _addressSpaces; private static HvIpaAllocator _ipaAllocator; - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); public static (ulong, HvIpaAllocator) CreateAddressSpace(MemoryBlock block) { diff --git a/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs b/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs index 6f1191ca58..d4f68eb652 100644 --- a/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs +++ b/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; +using System.Threading; namespace Ryujinx.Cpu.LightningJit.Cache { @@ -23,7 +24,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache private static readonly List _cacheEntries = new(); - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static bool _initialized; [SupportedOSPlatform("windows")] diff --git a/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs b/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs index a710749959..573af359f2 100644 --- a/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs +++ b/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs @@ -4,6 +4,7 @@ using Ryujinx.Memory; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading; namespace Ryujinx.Cpu.LightningJit.Cache { @@ -104,7 +105,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache private readonly MemoryCache _sharedCache; private readonly MemoryCache _localCache; private readonly PageAlignedRangeList _pendingMap; - private readonly object _lock; + private readonly Lock _lock; class ThreadLocalCacheEntry { diff --git a/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs b/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs index 93e6083298..e467710d7b 100644 --- a/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs +++ b/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Threading; namespace Ryujinx.Cpu.Signal { @@ -59,7 +60,7 @@ namespace Ryujinx.Cpu.Signal private static MemoryBlock _codeBlock; - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static bool _initialized; static NativeSignalHandler() diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs index cc3d2e5c11..05e57bfdfa 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs @@ -56,7 +56,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading private int _refConsumerPtr; private Action _interruptAction; - private readonly object _interruptLock = new(); + private readonly Lock _interruptLock = new(); public event EventHandler ScreenCaptured; diff --git a/src/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs b/src/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs index d330de638a..825b8fe18f 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs @@ -2,6 +2,7 @@ using Ryujinx.Common.Pools; using Ryujinx.Memory.Range; using System; using System.Linq; +using System.Threading; namespace Ryujinx.Graphics.Gpu.Memory { @@ -76,7 +77,7 @@ namespace Ryujinx.Graphics.Gpu.Memory private BufferMigration _source; private BufferModifiedRangeList _migrationTarget; - private readonly object _lock = new(); + private readonly Lock _lock = new(); /// /// Whether the modified range list has any entries or not. diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index 345a99ffa1..7e0311407e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries private ulong _accumulatedCounter; private int _waiterCount; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly Queue _queryPool; private readonly AutoResetEvent _queuedEvent = new(false); diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index 32b75c615e..889517480b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries private bool _hostAccessReserved = false; private int _refCount = 1; // Starts with a reference from the counter queue. - private readonly object _lock = new(); + private readonly Lock _lock = new(); private ulong _result = ulong.MaxValue; private double _divisor = 1f; diff --git a/src/Ryujinx.Graphics.OpenGL/ResourcePool.cs b/src/Ryujinx.Graphics.OpenGL/ResourcePool.cs index 6385f57b56..c8ff30a07c 100644 --- a/src/Ryujinx.Graphics.OpenGL/ResourcePool.cs +++ b/src/Ryujinx.Graphics.OpenGL/ResourcePool.cs @@ -2,6 +2,7 @@ using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using System; using System.Collections.Generic; +using System.Threading; namespace Ryujinx.Graphics.OpenGL { @@ -19,7 +20,7 @@ namespace Ryujinx.Graphics.OpenGL { private const int DisposedLiveFrames = 2; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly Dictionary> _textures = new(); /// diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs index b259dde28c..e707aacafd 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs @@ -4,6 +4,7 @@ using Ryujinx.Graphics.Shader.StructuredIr; using Ryujinx.Graphics.Shader.Translation; using System; using System.Collections.Generic; +using System.Threading; using static Spv.Specification; namespace Ryujinx.Graphics.Shader.CodeGen.Spirv @@ -19,13 +20,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv private const int GeneratorPoolCount = 1; private static readonly ObjectPool _instructionPool; private static readonly ObjectPool _integerPool; - private static readonly object _poolLock; + private static readonly Lock _poolLock; static SpirvGenerator() { _instructionPool = new(() => new SpvInstructionPool(), GeneratorPoolCount); _integerPool = new(() => new SpvLiteralIntegerPool(), GeneratorPoolCount); - _poolLock = new object(); + _poolLock = new Lock(); } private const HelperFunctionsMask NeedsInvocationIdMask = HelperFunctionsMask.SwizzleAdd; diff --git a/src/Ryujinx.Graphics.Vulkan/BackgroundResources.cs b/src/Ryujinx.Graphics.Vulkan/BackgroundResources.cs index 0290987fdb..e4b68fa404 100644 --- a/src/Ryujinx.Graphics.Vulkan/BackgroundResources.cs +++ b/src/Ryujinx.Graphics.Vulkan/BackgroundResources.cs @@ -25,7 +25,7 @@ namespace Ryujinx.Graphics.Vulkan { bool useBackground = _gd.BackgroundQueue.Handle != 0 && _gd.Vendor != Vendor.Amd; Queue queue = useBackground ? _gd.BackgroundQueue : _gd.Queue; - object queueLock = useBackground ? _gd.BackgroundQueueLock : _gd.QueueLock; + Lock queueLock = useBackground ? _gd.BackgroundQueueLock : _gd.QueueLock; lock (queueLock) { diff --git a/src/Ryujinx.Graphics.Vulkan/CommandBufferPool.cs b/src/Ryujinx.Graphics.Vulkan/CommandBufferPool.cs index e3938392f2..b32058bb49 100644 --- a/src/Ryujinx.Graphics.Vulkan/CommandBufferPool.cs +++ b/src/Ryujinx.Graphics.Vulkan/CommandBufferPool.cs @@ -17,7 +17,7 @@ namespace Ryujinx.Graphics.Vulkan private readonly Vk _api; private readonly Device _device; private readonly Queue _queue; - private readonly object _queueLock; + private readonly Lock _queueLock; private readonly bool _concurrentFenceWaitUnsupported; private readonly CommandPool _pool; private readonly Thread _owner; @@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.Vulkan Vk api, Device device, Queue queue, - object queueLock, + Lock queueLock, uint queueFamilyIndex, bool concurrentFenceWaitUnsupported, bool isLight = false) diff --git a/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs b/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs index baccc698f2..420bb53c07 100644 --- a/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs +++ b/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs @@ -5,6 +5,7 @@ using Silk.NET.Vulkan; using Silk.NET.Vulkan.Extensions.EXT; using System; using System.Collections.Generic; +using System.Threading; namespace Ryujinx.Graphics.Vulkan { @@ -31,7 +32,7 @@ namespace Ryujinx.Graphics.Vulkan private readonly Vk _api; private readonly ExtExternalMemoryHost _hostMemoryApi; private readonly Device _device; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly List _allocations; private readonly IntervalTree _allocationTree; diff --git a/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs index 0d133e50ec..fa10f13b96 100644 --- a/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries private ulong _accumulatedCounter; private int _waiterCount; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly Queue _queryPool; private readonly AutoResetEvent _queuedEvent = new(false); diff --git a/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs index 14d3050bfd..0bac3be121 100644 --- a/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs @@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries private bool _hostAccessReserved; private int _refCount = 1; // Starts with a reference from the counter queue. - private readonly object _lock = new(); + private readonly Lock _lock = new(); private ulong _result = ulong.MaxValue; private double _divisor = 1f; diff --git a/src/Ryujinx.Graphics.Vulkan/Shader.cs b/src/Ryujinx.Graphics.Vulkan/Shader.cs index 06f3499db9..5e9e813f52 100644 --- a/src/Ryujinx.Graphics.Vulkan/Shader.cs +++ b/src/Ryujinx.Graphics.Vulkan/Shader.cs @@ -5,6 +5,7 @@ using shaderc; using Silk.NET.Vulkan; using System; using System.Runtime.InteropServices; +using System.Threading; using System.Threading.Tasks; namespace Ryujinx.Graphics.Vulkan @@ -13,7 +14,7 @@ namespace Ryujinx.Graphics.Vulkan { // The shaderc.net dependency's Options constructor and dispose are not thread safe. // Take this lock when using them. - private static readonly object _shaderOptionsLock = new(); + private static readonly Lock _shaderOptionsLock = new(); private static readonly IntPtr _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main"); diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs index c9ce678b77..c8ede283ea 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs @@ -11,6 +11,7 @@ using Silk.NET.Vulkan.Extensions.KHR; using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Threading; using Format = Ryujinx.Graphics.GAL.Format; using PrimitiveTopology = Ryujinx.Graphics.GAL.PrimitiveTopology; using SamplerCreateInfo = Ryujinx.Graphics.GAL.SamplerCreateInfo; @@ -42,8 +43,8 @@ namespace Ryujinx.Graphics.Vulkan internal uint QueueFamilyIndex { get; private set; } internal Queue Queue { get; private set; } internal Queue BackgroundQueue { get; private set; } - internal object BackgroundQueueLock { get; private set; } - internal object QueueLock { get; private set; } + internal Lock BackgroundQueueLock { get; private set; } + internal Lock QueueLock { get; private set; } internal MemoryAllocator MemoryAllocator { get; private set; } internal HostMemoryAllocator HostMemoryAllocator { get; private set; } @@ -153,7 +154,7 @@ namespace Ryujinx.Graphics.Vulkan { Api.GetDeviceQueue(_device, queueFamilyIndex, 1, out var backgroundQueue); BackgroundQueue = backgroundQueue; - BackgroundQueueLock = new object(); + BackgroundQueueLock = new Lock(); } PhysicalDeviceProperties2 properties2 = new() @@ -458,7 +459,7 @@ namespace Ryujinx.Graphics.Vulkan Api.GetDeviceQueue(_device, queueFamilyIndex, 0, out var queue); Queue = queue; - QueueLock = new object(); + QueueLock = new Lock(); LoadFeatures(maxQueueCount, queueFamilyIndex); diff --git a/src/Ryujinx.Gtk3/Input/GTK3/GTK3Keyboard.cs b/src/Ryujinx.Gtk3/Input/GTK3/GTK3Keyboard.cs index ff7a2c3b6c..33857e0e88 100644 --- a/src/Ryujinx.Gtk3/Input/GTK3/GTK3Keyboard.cs +++ b/src/Ryujinx.Gtk3/Input/GTK3/GTK3Keyboard.cs @@ -3,6 +3,7 @@ using Ryujinx.Common.Configuration.Hid.Keyboard; using System; using System.Collections.Generic; using System.Numerics; +using System.Threading; using ConfigKey = Ryujinx.Common.Configuration.Hid.Key; namespace Ryujinx.Input.GTK3 @@ -21,7 +22,7 @@ namespace Ryujinx.Input.GTK3 } } - private readonly object _userMappingLock = new(); + private readonly Lock _userMappingLock = new(); private readonly GTK3KeyboardDriver _driver; private StandardKeyboardInputConfig _configuration; diff --git a/src/Ryujinx.HLE/FileSystem/ContentManager.cs b/src/Ryujinx.HLE/FileSystem/ContentManager.cs index e6c0fce081..297031141b 100644 --- a/src/Ryujinx.HLE/FileSystem/ContentManager.cs +++ b/src/Ryujinx.HLE/FileSystem/ContentManager.cs @@ -21,6 +21,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Text; +using System.Threading; using Path = System.IO.Path; namespace Ryujinx.HLE.FileSystem @@ -54,7 +55,7 @@ namespace Ryujinx.HLE.FileSystem private readonly VirtualFileSystem _virtualFileSystem; - private readonly object _lock = new(); + private readonly Lock _lock = new(); public ContentManager(VirtualFileSystem virtualFileSystem) { diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs index 0462a5b003..7a572d21c2 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs @@ -14,6 +14,7 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; +using System.Threading; namespace Ryujinx.HLE.HOS.Applets { @@ -62,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Applets private bool _canAcceptController = false; private KeyboardInputMode _inputMode = KeyboardInputMode.ControllerAndKeyboard; - private readonly object _lock = new(); + private readonly Lock _lock = new(); public event EventHandler AppletStateChanged; diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs index 9e48568e13..45470fd425 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs @@ -11,6 +11,7 @@ using System.IO; using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; +using System.Threading; namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { @@ -26,7 +27,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 Image _surface = null; diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs index 3eaf64596e..a8b137df2c 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs @@ -27,7 +27,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard private TRef _cancelled = null; private Thread _thread = null; - private readonly object _lock = new(); + private readonly Lock _lock = new(); public bool IsRunning { diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NodeLatestUpdate.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NodeLatestUpdate.cs index 0461e783ee..826a50458d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NodeLatestUpdate.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NodeLatestUpdate.cs @@ -1,5 +1,6 @@ using Ryujinx.Common.Memory; using System.Runtime.InteropServices; +using System.Threading; namespace Ryujinx.HLE.HOS.Services.Ldn.Types { @@ -12,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.Types static class NodeLatestUpdateHelper { - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); public static void CalculateLatestUpdate(this Array8 array, Array8 beforeNodes, Array8 afterNodes) { diff --git a/src/Ryujinx.HLE/PerformanceStatistics.cs b/src/Ryujinx.HLE/PerformanceStatistics.cs index 3767a7fb4d..f674298e69 100644 --- a/src/Ryujinx.HLE/PerformanceStatistics.cs +++ b/src/Ryujinx.HLE/PerformanceStatistics.cs @@ -1,5 +1,7 @@ using Ryujinx.Common; +using System.Threading; using System.Timers; +using Timer = System.Timers.Timer; namespace Ryujinx.HLE { @@ -20,8 +22,8 @@ namespace Ryujinx.HLE private readonly long[] _framesRendered; private readonly double[] _percentTime; - private readonly object[] _frameLock; - private readonly object[] _percentLock; + private readonly Lock[] _frameLock; + private readonly Lock[] _percentLock; private readonly double _ticksToSeconds; @@ -41,8 +43,8 @@ namespace Ryujinx.HLE _framesRendered = new long[1]; _percentTime = new double[1]; - _frameLock = new[] { new object() }; - _percentLock = new[] { new object() }; + _frameLock = new[] { new Lock() }; + _percentLock = new[] { new Lock() }; _resetTimer = new Timer(750); diff --git a/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs b/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs index 534bf63ed6..585b40df38 100644 --- a/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs +++ b/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs @@ -4,6 +4,7 @@ using Ryujinx.Horizon.Sdk.OsTypes; using Ryujinx.Horizon.Sdk.Sf; using System; using System.Collections.Generic; +using System.Threading; namespace Ryujinx.Horizon.Sdk.Friends.Detail.Ipc { @@ -13,7 +14,7 @@ namespace Ryujinx.Horizon.Sdk.Friends.Detail.Ipc private readonly Uid _userId; private readonly FriendsServicePermissionLevel _permissionLevel; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private SystemEventType _notificationEvent; diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs index 4063520039..879a3a58fd 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs @@ -2,6 +2,7 @@ using Ryujinx.Common; using Ryujinx.Horizon.Common; using System; using System.Collections.Generic; +using System.Threading; namespace Ryujinx.Horizon.Sdk.OsTypes.Impl { @@ -13,7 +14,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl private readonly List _multiWaits; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private int _waitingThreadHandle; diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs index 7762345af6..a8385a17fa 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,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif } private readonly EntryManager _entryManager; - private readonly object _entryOwnerLock; + private readonly Lock _entryOwnerLock; private readonly HashSet _domains; private readonly int _maxDomains; public ServerDomainManager(int entryCount, int maxDomains) { _entryManager = new EntryManager(entryCount); - _entryOwnerLock = new object(); + _entryOwnerLock = new Lock(); _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 e8957b758e..ba37fa1376 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; private readonly ulong[] _sessionAllocationBitmap; private readonly HashSet _sessions; private readonly HashSet _servers; @@ -42,7 +43,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc } } - _resourceLock = new object(); + _resourceLock = new Lock(); _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 570e3c8028..e79846fdd8 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; + private readonly Lock _waitListLock; private readonly Event _requestStopEvent; private readonly Event _notifyEvent; @@ -39,8 +40,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc _multiWait = new MultiWait(); _waitList = new MultiWait(); - _multiWaitSelectionLock = new object(); - _waitListLock = new object(); + _multiWaitSelectionLock = new Lock(); + _waitListLock = new Lock(); _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 187ca48dd7..d635b87856 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 @@ -55,7 +56,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/SDL2GamepadDriver.cs b/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs index c741493c1a..f6ccd40a7a 100644 --- a/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs +++ b/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs @@ -1,6 +1,7 @@ using Ryujinx.SDL2.Common; using System; using System.Collections.Generic; +using System.Threading; using static SDL2.SDL; namespace Ryujinx.Input.SDL2 @@ -9,7 +10,7 @@ namespace Ryujinx.Input.SDL2 { private readonly Dictionary _gamepadsInstanceIdsMapping; private readonly List _gamepadsIds; - private readonly object _lock = new object(); + private readonly Lock _lock = new(); public ReadOnlySpan GamepadsIds { diff --git a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs index bc0a7e6607..ee7f6fa888 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; @@ -24,7 +25,7 @@ namespace Ryujinx.Input.SDL2 } } - 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.Input/HLE/NpadManager.cs b/src/Ryujinx.Input/HLE/NpadManager.cs index 1dc87358d5..a77aa2168d 100644 --- a/src/Ryujinx.Input/HLE/NpadManager.cs +++ b/src/Ryujinx.Input/HLE/NpadManager.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; +using System.Threading; using CemuHookClient = Ryujinx.Input.Motion.CemuHook.Client; using ControllerType = Ryujinx.Common.Configuration.Hid.ControllerType; using PlayerIndex = Ryujinx.HLE.HOS.Services.Hid.PlayerIndex; @@ -18,7 +19,7 @@ namespace Ryujinx.Input.HLE { private readonly CemuHookClient _cemuHookClient; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private bool _blockInputUpdates; diff --git a/src/Ryujinx.Memory/Tracking/MemoryTracking.cs b/src/Ryujinx.Memory/Tracking/MemoryTracking.cs index 96cb2c5f52..5a53058370 100644 --- a/src/Ryujinx.Memory/Tracking/MemoryTracking.cs +++ b/src/Ryujinx.Memory/Tracking/MemoryTracking.cs @@ -1,6 +1,7 @@ using Ryujinx.Common.Pools; using Ryujinx.Memory.Range; using System.Collections.Generic; +using System.Threading; namespace Ryujinx.Memory.Tracking { @@ -26,7 +27,7 @@ namespace Ryujinx.Memory.Tracking /// This lock must be obtained when traversing or updating the region-handle hierarchy. /// It is not required when reading dirty flags. /// - internal object TrackingLock = new(); + internal Lock TrackingLock = new(); /// /// Create a new tracking structure for the given "physical" memory block, diff --git a/src/Ryujinx.Memory/Tracking/RegionHandle.cs b/src/Ryujinx.Memory/Tracking/RegionHandle.cs index a94ffa43c8..deb83aebdc 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; @@ -278,7 +278,7 @@ namespace Ryujinx.Memory.Tracking } // Temporarily release the tracking lock while we're running the action. - Monitor.Exit(_tracking.TrackingLock); + _tracking.TrackingLock.Exit(); try { @@ -293,7 +293,7 @@ namespace Ryujinx.Memory.Tracking } finally { - Monitor.Enter(_tracking.TrackingLock); + _tracking.TrackingLock.Enter(); } } diff --git a/src/Ryujinx.SDL2.Common/SDL2Driver.cs b/src/Ryujinx.SDL2.Common/SDL2Driver.cs index ed6d941908..b4dfe58902 100644 --- a/src/Ryujinx.SDL2.Common/SDL2Driver.cs +++ b/src/Ryujinx.SDL2.Common/SDL2Driver.cs @@ -36,7 +36,7 @@ namespace Ryujinx.SDL2.Common private ConcurrentDictionary> _registeredWindowHandlers; - private readonly object _lock = new(); + private readonly Lock _lock = new(); private SDL2Driver() { } diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index 0db8ef4143..21faca2f9f 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -117,7 +117,7 @@ namespace Ryujinx.Ava private bool _dialogShown; private readonly bool _isFirmwareTitle; - private readonly object _lockObject = new(); + private readonly Lock _lock = new(); public event EventHandler AppExit; public event EventHandler StatusInitEvent; @@ -339,7 +339,7 @@ namespace Ryujinx.Ava { Task.Run(() => { - lock (_lockObject) + lock (_lock) { string applicationName = Device.Processes.ActiveApplication.Name; string sanitizedApplicationName = FileSystemUtils.SanitizeFileName(applicationName); diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs index ff88de79e4..7c82519ed7 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; }