revert the explicit try/finally use for PeekByte/PokeByte monitor domain methods, testing seems to show the ref struct use makes EnterExit allocation (now forced to the stack) a non-issue performance wise
This commit is contained in:
parent
f01463e2b3
commit
3dd36f5f07
|
@ -15,11 +15,12 @@ namespace BizHawk.Common
|
|||
=> new(m);
|
||||
|
||||
public readonly ref struct EnterExitWrapper
|
||||
{
|
||||
// yes, this can be null
|
||||
private readonly IMonitor? _m;
|
||||
|
||||
public EnterExitWrapper(IMonitor? m)
|
||||
{
|
||||
// yes, this can be null
|
||||
private readonly IMonitor? _m;
|
||||
|
||||
// disallow public construction outside of EnterExit extension
|
||||
internal EnterExitWrapper(IMonitor? m)
|
||||
{
|
||||
_m = m;
|
||||
_m?.Enter();
|
||||
|
|
|
@ -251,15 +251,10 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
return ((byte*)Data)[addr];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(addr));
|
||||
|
@ -271,15 +266,10 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
((byte*)Data)[addr] = val;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -361,15 +351,10 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
return ((byte*)Data)[addr ^ 1];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(addr));
|
||||
|
@ -381,15 +366,10 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
((byte*)Data)[addr ^ 1] = val;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -35,38 +35,18 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
|
|||
|
||||
public override byte PeekByte(long addr)
|
||||
{
|
||||
if (addr < 0 || addr >= _systemBusSize) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
|
||||
|
||||
if ((ulong)addr < (ulong)_systemBusSize) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
|
||||
addr += _firstOffset;
|
||||
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
return _core.mame_read_byte((uint)addr << _systemBusAddressShift);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
return _core.mame_read_byte((uint)addr << _systemBusAddressShift);
|
||||
}
|
||||
|
||||
public override void PokeByte(long addr, byte val)
|
||||
{
|
||||
if (Writable)
|
||||
{
|
||||
if (addr < 0 || addr >= _systemBusSize) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
|
||||
|
||||
if ((ulong)addr < (ulong)_systemBusSize) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
|
||||
addr += _firstOffset;
|
||||
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
_core.mame_lua_execute($"{MAMELuaCommand.GetSpace}:write_u8({addr << _systemBusAddressShift}, {val})");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
_core.mame_lua_execute($"{MAMELuaCommand.GetSpace}:write_u8({addr << _systemBusAddressShift}, {val})");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
public static WaterboxMemoryDomain Create(MemoryArea m, WaterboxHost monitor)
|
||||
{
|
||||
return m.Flags.HasFlag(MemoryDomainFlags.FunctionHook)
|
||||
? (WaterboxMemoryDomain)new WaterboxMemoryDomainFunc(m, monitor)
|
||||
? new WaterboxMemoryDomainFunc(m, monitor)
|
||||
: new WaterboxMemoryDomainPointer(m, monitor);
|
||||
}
|
||||
|
||||
|
@ -73,15 +73,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
return ((byte*)_data)[addr ^ _addressMangler];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(addr));
|
||||
|
@ -93,15 +88,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
((byte*)_data)[addr ^ _addressMangler] = val;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -123,15 +113,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
if (start < (ulong)Size && (start + count) <= (ulong)Size)
|
||||
{
|
||||
try
|
||||
using (_monitor.EnterExit())
|
||||
{
|
||||
_monitor.Enter();
|
||||
Marshal.Copy(Z.US((ulong)_data + start), values, 0, (int)count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue