2018-11-28 22:18:09 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
{
|
|
|
|
class KSlabHeap
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
private LinkedList<ulong> Items;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public KSlabHeap(ulong Pa, ulong ItemSize, ulong Size)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Items = new LinkedList<ulong>();
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
int ItemsCount = (int)(Size / ItemSize);
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
for (int Index = 0; Index < ItemsCount; Index++)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Items.AddLast(Pa);
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Pa += ItemSize;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public bool TryGetItem(out ulong Pa)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
lock (Items)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if (Items.First != null)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Pa = Items.First.Value;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Items.RemoveFirst();
|
2018-11-28 22:18:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Pa = 0;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void Free(ulong Pa)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
lock (Items)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Items.AddFirst(Pa);
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|