* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0052 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA1069 warnings * Address remaining dotnet format analyzer warnings * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Revert formatting changes for while and for-loops * Another rebase, another dotnet format run * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Address review feedback * Add trailing commas * Remove SuppressMessage for IDE0066 * Make explicit Equals implementation implicit
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using Ryujinx.Graphics.GAL.Multithreading.Commands.CounterEvent;
|
|
using Ryujinx.Graphics.GAL.Multithreading.Model;
|
|
using System.Threading;
|
|
|
|
namespace Ryujinx.Graphics.GAL.Multithreading.Resources
|
|
{
|
|
class ThreadedCounterEvent : ICounterEvent
|
|
{
|
|
private readonly ThreadedRenderer _renderer;
|
|
public ICounterEvent Base;
|
|
|
|
public bool Invalid { get; set; }
|
|
|
|
public CounterType Type { get; }
|
|
public bool ClearCounter { get; }
|
|
|
|
private bool _reserved;
|
|
private int _createLock;
|
|
|
|
public ThreadedCounterEvent(ThreadedRenderer renderer, CounterType type, bool clearCounter)
|
|
{
|
|
_renderer = renderer;
|
|
Type = type;
|
|
ClearCounter = clearCounter;
|
|
}
|
|
|
|
private TableRef<T> Ref<T>(T reference)
|
|
{
|
|
return new TableRef<T>(_renderer, reference);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_renderer.New<CounterEventDisposeCommand>().Set(Ref(this));
|
|
_renderer.QueueCommand();
|
|
}
|
|
|
|
public void Flush()
|
|
{
|
|
ThreadedHelpers.SpinUntilNonNull(ref Base);
|
|
|
|
Base.Flush();
|
|
}
|
|
|
|
public bool ReserveForHostAccess()
|
|
{
|
|
if (Base != null)
|
|
{
|
|
return Base.ReserveForHostAccess();
|
|
}
|
|
else
|
|
{
|
|
bool result = true;
|
|
|
|
// A very light lock, as this case is uncommon.
|
|
ThreadedHelpers.SpinUntilExchange(ref _createLock, 1, 0);
|
|
|
|
if (Base != null)
|
|
{
|
|
result = Base.ReserveForHostAccess();
|
|
}
|
|
else
|
|
{
|
|
_reserved = true;
|
|
}
|
|
|
|
Volatile.Write(ref _createLock, 0);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public void Create(IRenderer renderer, CounterType type, System.EventHandler<ulong> eventHandler, bool hostReserved)
|
|
{
|
|
ThreadedHelpers.SpinUntilExchange(ref _createLock, 1, 0);
|
|
Base = renderer.ReportCounter(type, eventHandler, hostReserved || _reserved);
|
|
Volatile.Write(ref _createLock, 0);
|
|
}
|
|
}
|
|
}
|