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