2018-02-17 22:36:08 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-02-20 21:09:23 +01:00
|
|
|
namespace Ryujinx.Core.OsHle.Handles
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
class HSharedMem
|
|
|
|
{
|
2018-02-17 22:36:08 +01:00
|
|
|
private List<long> Positions;
|
|
|
|
|
|
|
|
public int PositionsCount => Positions.Count;
|
|
|
|
|
|
|
|
public EventHandler<EventArgs> MemoryMapped;
|
|
|
|
public EventHandler<EventArgs> MemoryUnmapped;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
public HSharedMem(long PhysPos)
|
|
|
|
{
|
2018-02-17 22:36:08 +01:00
|
|
|
Positions = new List<long>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddVirtualPosition(long Position)
|
|
|
|
{
|
|
|
|
lock (Positions)
|
|
|
|
{
|
|
|
|
Positions.Add(Position);
|
|
|
|
|
2018-02-20 11:54:00 +01:00
|
|
|
MemoryMapped?.Invoke(this, EventArgs.Empty);
|
2018-02-17 22:36:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveVirtualPosition(long Position)
|
|
|
|
{
|
|
|
|
lock (Positions)
|
|
|
|
{
|
|
|
|
Positions.Remove(Position);
|
|
|
|
|
2018-02-20 11:54:00 +01:00
|
|
|
MemoryUnmapped?.Invoke(this, EventArgs.Empty);
|
2018-02-17 22:36:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public long GetVirtualPosition(int Index)
|
|
|
|
{
|
|
|
|
lock (Positions)
|
|
|
|
{
|
|
|
|
if (Index < 0 || Index >= Positions.Count)
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Positions[Index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryGetLastVirtualPosition(out long Position)
|
|
|
|
{
|
|
|
|
lock (Positions)
|
|
|
|
{
|
|
|
|
if (Positions.Count > 0)
|
|
|
|
{
|
|
|
|
Position = Positions[Positions.Count - 1];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Position = 0;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|