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