Ryujinx/Ryujinx.HLE/HOS/Kernel/KSlabHeap.cs

50 lines
1,003 B
C#
Raw Normal View History

using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Kernel
{
class KSlabHeap
{
2018-12-01 21:01:59 +01:00
private LinkedList<ulong> _items;
2018-12-01 21:01:59 +01:00
public KSlabHeap(ulong pa, ulong itemSize, ulong size)
{
2018-12-01 21:01:59 +01:00
_items = new LinkedList<ulong>();
2018-12-01 21:01:59 +01:00
int itemsCount = (int)(size / itemSize);
2018-12-01 21:01:59 +01:00
for (int index = 0; index < itemsCount; index++)
{
2018-12-01 21:01:59 +01:00
_items.AddLast(pa);
2018-12-01 21:01:59 +01:00
pa += itemSize;
}
}
2018-12-01 21:01:59 +01:00
public bool TryGetItem(out ulong pa)
{
2018-12-01 21:01:59 +01:00
lock (_items)
{
2018-12-01 21:01:59 +01:00
if (_items.First != null)
{
2018-12-01 21:01:59 +01:00
pa = _items.First.Value;
2018-12-01 21:01:59 +01:00
_items.RemoveFirst();
return true;
}
}
2018-12-01 21:01:59 +01:00
pa = 0;
return false;
}
2018-12-01 21:01:59 +01:00
public void Free(ulong pa)
{
2018-12-01 21:01:59 +01:00
lock (_items)
{
2018-12-01 21:01:59 +01:00
_items.AddFirst(pa);
}
}
}
}