1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-02 21:42:02 +00:00
Ryujinx/Ryujinx.HLE/HOS/Kernel/KPageList.cs

80 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Kernel
{
class KPageList : IEnumerable<KPageNode>
{
public LinkedList<KPageNode> Nodes { get; private set; }
public KPageList()
{
Nodes = new LinkedList<KPageNode>();
}
2018-12-01 20:01:59 +00:00
public KernelResult AddRange(ulong address, ulong pagesCount)
{
2018-12-01 20:01:59 +00:00
if (pagesCount != 0)
{
if (Nodes.Last != null)
{
2018-12-01 20:01:59 +00:00
KPageNode lastNode = Nodes.Last.Value;
2018-12-01 20:01:59 +00:00
if (lastNode.Address + lastNode.PagesCount * KMemoryManager.PageSize == address)
{
2018-12-01 20:01:59 +00:00
address = lastNode.Address;
pagesCount += lastNode.PagesCount;
Nodes.RemoveLast();
}
}
2018-12-01 20:01:59 +00:00
Nodes.AddLast(new KPageNode(address, pagesCount));
}
return KernelResult.Success;
}
public ulong GetPagesCount()
{
2018-12-01 20:01:59 +00:00
ulong sum = 0;
2018-12-01 20:01:59 +00:00
foreach (KPageNode node in Nodes)
{
2018-12-01 20:01:59 +00:00
sum += node.PagesCount;
}
2018-12-01 20:01:59 +00:00
return sum;
}
2018-12-01 20:01:59 +00:00
public bool IsEqual(KPageList other)
{
2018-12-01 20:01:59 +00:00
LinkedListNode<KPageNode> thisNode = Nodes.First;
LinkedListNode<KPageNode> otherNode = other.Nodes.First;
2018-12-01 20:01:59 +00:00
while (thisNode != null && otherNode != null)
{
2018-12-01 20:01:59 +00:00
if (thisNode.Value.Address != otherNode.Value.Address ||
thisNode.Value.PagesCount != otherNode.Value.PagesCount)
{
return false;
}
2018-12-01 20:01:59 +00:00
thisNode = thisNode.Next;
otherNode = otherNode.Next;
}
2018-12-01 20:01:59 +00:00
return thisNode == null && otherNode == null;
}
public IEnumerator<KPageNode> GetEnumerator()
{
return Nodes.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}