2020-07-11 20:07:01 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
2020-12-01 15:23:43 -08:00
|
|
|
|
namespace Ryujinx.Memory
|
2020-07-11 20:07:01 -07:00
|
|
|
|
{
|
|
|
|
|
public sealed class WritableRegion : IDisposable
|
|
|
|
|
{
|
2021-01-17 10:44:34 -08:00
|
|
|
|
private readonly IWritableBlock _block;
|
2020-07-11 20:07:01 -07:00
|
|
|
|
private readonly ulong _va;
|
|
|
|
|
|
2021-01-17 10:44:34 -08:00
|
|
|
|
private bool NeedsWriteback => _block != null;
|
2020-07-11 20:07:01 -07:00
|
|
|
|
|
|
|
|
|
public Memory<byte> Memory { get; }
|
|
|
|
|
|
2021-01-17 10:44:34 -08:00
|
|
|
|
public WritableRegion(IWritableBlock block, ulong va, Memory<byte> memory)
|
2020-07-11 20:07:01 -07:00
|
|
|
|
{
|
2021-01-17 10:44:34 -08:00
|
|
|
|
_block = block;
|
2020-07-11 20:07:01 -07:00
|
|
|
|
_va = va;
|
|
|
|
|
Memory = memory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (NeedsWriteback)
|
|
|
|
|
{
|
2021-01-17 10:44:34 -08:00
|
|
|
|
_block.Write(_va, Memory.Span);
|
2020-07-11 20:07:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|