Ryujinx.Tests.Unicorn: Implement IDisposable (#3794)

Dispose unicorn when done
This commit is contained in:
merry 2022-10-24 00:51:54 +01:00 committed by GitHub
parent 9b06ee7736
commit eafadf10c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 4 deletions

View file

@ -3,9 +3,10 @@ using System;
namespace Ryujinx.Tests.Unicorn namespace Ryujinx.Tests.Unicorn
{ {
public class UnicornAArch32 public class UnicornAArch32 : IDisposable
{ {
internal readonly IntPtr uc; internal readonly IntPtr uc;
private bool _isDisposed = false;
public IndexedProperty<int, uint> R public IndexedProperty<int, uint> R
{ {
@ -106,8 +107,23 @@ namespace Ryujinx.Tests.Unicorn
} }
~UnicornAArch32() ~UnicornAArch32()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
{ {
Interface.Checked(Native.Interface.uc_close(uc)); Interface.Checked(Native.Interface.uc_close(uc));
_isDisposed = true;
}
} }
public void RunForCount(ulong count) public void RunForCount(ulong count)

View file

@ -3,9 +3,10 @@ using System;
namespace Ryujinx.Tests.Unicorn namespace Ryujinx.Tests.Unicorn
{ {
public class UnicornAArch64 public class UnicornAArch64 : IDisposable
{ {
internal readonly IntPtr uc; internal readonly IntPtr uc;
private bool _isDisposed = false;
public IndexedProperty<int, ulong> X public IndexedProperty<int, ulong> X
{ {
@ -95,8 +96,23 @@ namespace Ryujinx.Tests.Unicorn
} }
~UnicornAArch64() ~UnicornAArch64()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
{ {
Interface.Checked(Native.Interface.uc_close(uc)); Interface.Checked(Native.Interface.uc_close(uc));
_isDisposed = true;
}
} }
public void RunForCount(ulong count) public void RunForCount(ulong count)

View file

@ -80,6 +80,12 @@ namespace Ryujinx.Tests.Cpu
[TearDown] [TearDown]
public void Teardown() public void Teardown()
{ {
if (_unicornAvailable)
{
_unicornEmu.Dispose();
_unicornEmu = null;
}
_memory.DecrementReferenceCount(); _memory.DecrementReferenceCount();
_context.Dispose(); _context.Dispose();
_ram.Dispose(); _ram.Dispose();

View file

@ -76,6 +76,12 @@ namespace Ryujinx.Tests.Cpu
[TearDown] [TearDown]
public void Teardown() public void Teardown()
{ {
if (_unicornAvailable)
{
_unicornEmu.Dispose();
_unicornEmu = null;
}
_memory.DecrementReferenceCount(); _memory.DecrementReferenceCount();
_context.Dispose(); _context.Dispose();
_ram.Dispose(); _ram.Dispose();