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