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