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