Skip to content

Commit

Permalink
new Lock object
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-carvalho committed Nov 13, 2024
1 parent 9293cdd commit f9ea191
Show file tree
Hide file tree
Showing 46 changed files with 78 additions and 62 deletions.
3 changes: 2 additions & 1 deletion src/ARMeilleure/Translation/Cache/JitCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;

namespace ARMeilleure.Translation.Cache
{
Expand All @@ -26,7 +27,7 @@ static partial class JitCache

private static readonly List<CacheEntry> _cacheEntries = new();

private static readonly object _lock = new();
private static readonly Lock _lock = new();
private static bool _initialized;

[SupportedOSPlatform("windows")]
Expand Down
10 changes: 4 additions & 6 deletions src/ARMeilleure/Translation/PTC/Ptc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Ptc : IPtcLoadState

private readonly ManualResetEvent _waitEvent;

private readonly object _lock;
private readonly Lock _lock = new();

private bool _disposed;

Expand Down Expand Up @@ -88,8 +88,6 @@ public Ptc()

_waitEvent = new ManualResetEvent(true);

_lock = new object();

_disposed = false;

TitleIdText = TitleIdTextDefault;
Expand Down Expand Up @@ -851,11 +849,11 @@ void TranslateFuncs()


List<Thread> threads = Enumerable.Range(0, degreeOfParallelism)
.Select(idx =>
.Select(idx =>
new Thread(TranslateFuncs)
{
IsBackground = true,
Name = "Ptc.TranslateThread." + idx
IsBackground = true,
Name = "Ptc.TranslateThread." + idx
}
).ToList();

Expand Down
4 changes: 1 addition & 3 deletions src/ARMeilleure/Translation/PTC/PtcProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PtcProfiler

private readonly ManualResetEvent _waitEvent;

private readonly object _lock;
private readonly Lock _lock = new();

private bool _disposed;

Expand All @@ -65,8 +65,6 @@ public PtcProfiler(Ptc ptc)

_waitEvent = new ManualResetEvent(true);

_lock = new object();

_disposed = false;

ProfiledFuncs = new Dictionary<ulong, FuncProfile>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

namespace Ryujinx.Audio.Backends.OpenAL
{
Expand All @@ -18,7 +19,7 @@ class OpenALHardwareDeviceSession : HardwareDeviceSessionOutputBase
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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AudioManager : IDisposable
/// <summary>
/// Lock used to control the waiters registration.
/// </summary>
private readonly object _lock = new();
private readonly Lock _lock = new();

/// <summary>
/// Events signaled when the driver played audio buffers.
Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Ryujinx.Common.Memory;
using System;
using System.Buffers;
using System.Threading;

namespace Ryujinx.Audio.Backends.Common
{
Expand All @@ -12,7 +13,7 @@ public class DynamicRingBuffer
{
private const int RingBufferAlignment = 2048;

private readonly object _lock = new();
private readonly Lock _lock = new();

private MemoryOwner<byte> _bufferOwner;
private Memory<byte> _buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Audio/Input/AudioInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Ryujinx.Audio.Input
/// </summary>
public class AudioInputManager : IDisposable
{
private readonly object _lock = new();
private readonly Lock _lock = new();

/// <summary>
/// Lock used for session allocation.
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Audio/Output/AudioOutputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Ryujinx.Audio.Output
/// </summary>
public class AudioOutputManager : IDisposable
{
private readonly object _lock = new();
private readonly Lock _lock = new();

/// <summary>
/// Lock used for session allocation.
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Threading;

namespace Ryujinx.Audio.Renderer.Server.Upsampler
{
Expand All @@ -16,7 +17,7 @@ public class UpsamplerManager
/// <summary>
/// Global lock of the object.
/// </summary>
private readonly object _lock = new();
private readonly Lock _lock = new();

/// <summary>
/// The upsamplers instances.
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Common/PreciseSleep/NanosleepPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void Dispose()
}
}

private readonly object _lock = new();
private readonly Lock _lock = new();
private readonly List<NanosleepThread> _threads = new();
private readonly List<NanosleepThread> _active = new();
private readonly Stack<NanosleepThread> _free = new();
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Common/PreciseSleep/WindowsGranularTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public WaitingObject(long id, EventWaitHandle signal, long timePoint)
private long _lastTicks = PerformanceCounter.ElapsedTicks;
private long _lastId;

private readonly object _lock = new();
private readonly Lock _lock = new();
private readonly List<WaitingObject> _waitingObjects = new();

private WindowsGranularTimer()
Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.Cpu/AppleHv/HvVm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Ryujinx.Memory;
using System;
using System.Runtime.Versioning;
using System.Threading;

namespace Ryujinx.Cpu.AppleHv
{
Expand All @@ -12,7 +13,7 @@ static class HvVm

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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;

namespace Ryujinx.Cpu.LightningJit.Cache
{
Expand All @@ -23,7 +24,7 @@ static partial class JitCache

private static readonly List<CacheEntry> _cacheEntries = new();

private static readonly object _lock = new();
private static readonly Lock _lock = new();
private static bool _initialized;

[SupportedOSPlatform("windows")]
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

namespace Ryujinx.Cpu.LightningJit.Cache
{
Expand Down Expand Up @@ -104,7 +105,7 @@ public void Dispose()
private readonly MemoryCache _sharedCache;
private readonly MemoryCache _localCache;
private readonly PageAlignedRangeList _pendingMap;
private readonly object _lock;
private readonly Lock _lock = new();

class ThreadLocalCacheEntry
{
Expand Down Expand Up @@ -137,7 +138,6 @@ public NoWxCache(IJitMemoryAllocator allocator, IStackWalker stackWalker, Transl
_sharedCache = new(allocator, SharedCacheSize);
_localCache = new(allocator, LocalCacheSize);
_pendingMap = new(_sharedCache.ReprotectAsRx, RegisterFunction);
_lock = new();
}

public unsafe nint Map(nint framePointer, ReadOnlySpan<byte> code, ulong guestAddress, ulong guestSize)
Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;

namespace Ryujinx.Cpu.Signal
{
Expand Down Expand Up @@ -59,7 +60,7 @@ static class NativeSignalHandler

private static MemoryBlock _codeBlock;

private static readonly object _lock = new();
private static readonly Lock _lock = new();
private static bool _initialized;

static NativeSignalHandler()
Expand Down
5 changes: 3 additions & 2 deletions src/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Ryujinx.Memory.Range;
using System;
using System.Linq;
using System.Threading;

namespace Ryujinx.Graphics.Gpu.Memory
{
Expand Down Expand Up @@ -76,7 +77,7 @@ class BufferModifiedRangeList : RangeList<BufferModifiedRange>
private BufferMigration _source;
private BufferModifiedRangeList _migrationTarget;

private readonly object _lock = new();
private readonly Lock _lock = new();

/// <summary>
/// Whether the modified range list has any entries or not.
Expand Down Expand Up @@ -435,7 +436,7 @@ public void InheritRanges(BufferModifiedRangeList ranges, Action<ulong, ulong> r

if (_source == null)
{
// Create a new migration.
// Create a new migration.
_source = new BufferMigration(new BufferMigrationSpan[] { span }, this, _context.SyncNumber);

_context.RegisterBufferMigration(_source);
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CounterQueue : IDisposable
private ulong _accumulatedCounter;
private int _waiterCount;

private readonly object _lock = new();
private readonly Lock _lock = new();

private readonly Queue<BufferedQuery> _queryPool;
private readonly AutoResetEvent _queuedEvent = new(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CounterQueueEvent : ICounterEvent
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;

Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.Graphics.OpenGL/ResourcePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Ryujinx.Graphics.OpenGL.Image;
using System;
using System.Collections.Generic;
using System.Threading;

namespace Ryujinx.Graphics.OpenGL
{
Expand All @@ -19,7 +20,7 @@ class ResourcePool : IDisposable
{
private const int DisposedLiveFrames = 2;

private readonly object _lock = new();
private readonly Lock _lock = new();
private readonly Dictionary<TextureCreateInfo, List<DisposedTexture>> _textures = new();

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Silk.NET.Vulkan.Extensions.EXT;
using System;
using System.Collections.Generic;
using System.Threading;

namespace Ryujinx.Graphics.Vulkan
{
Expand All @@ -31,7 +32,7 @@ public HostMemoryAllocation(Auto<MemoryAllocation> allocation, nint pointer, ulo
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<HostMemoryAllocation> _allocations;
private readonly IntervalTree<ulong, HostMemoryAllocation> _allocationTree;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CounterQueue : IDisposable
private ulong _accumulatedCounter;
private int _waiterCount;

private readonly object _lock = new();
private readonly Lock _lock = new();

private readonly Queue<BufferedQuery> _queryPool;
private readonly AutoResetEvent _queuedEvent = new(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CounterQueueEvent : ICounterEvent
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;

Expand Down
3 changes: 2 additions & 1 deletion src/Ryujinx.HLE/FileSystem/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading;
using Path = System.IO.Path;

namespace Ryujinx.HLE.FileSystem
Expand Down Expand Up @@ -54,7 +55,7 @@ public AocItem(string containerPath, string ncaPath)

private readonly VirtualFileSystem _virtualFileSystem;

private readonly object _lock = new();
private readonly Lock _lock = new();

public ContentManager(VirtualFileSystem virtualFileSystem)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace Ryujinx.HLE.HOS.Applets
{
Expand Down Expand Up @@ -62,7 +63,7 @@ internal class SoftwareKeyboardApplet : IApplet
private bool _canAcceptController = false;
private KeyboardInputMode _inputMode = KeyboardInputMode.ControllerAndKeyboard;

private readonly object _lock = new();
private readonly Lock _lock = new();

public event EventHandler AppletStateChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public SleepSubstepData(int sleepMilliseconds)

private TRef<bool> _cancelled = null;
private Thread _thread = null;
private readonly object _lock = new();
private readonly Lock _lock = new();

public bool IsRunning
{
Expand Down
Loading

0 comments on commit f9ea191

Please sign in to comment.