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