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