mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-10-01 12:30:00 +02:00
50 lines
994 B
C#
50 lines
994 B
C#
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Ryujinx.HLE.HOS.Kernel
|
||
|
{
|
||
|
class KSlabHeap
|
||
|
{
|
||
|
private LinkedList<ulong> Items;
|
||
|
|
||
|
public KSlabHeap(ulong Pa, ulong ItemSize, ulong Size)
|
||
|
{
|
||
|
Items = new LinkedList<ulong>();
|
||
|
|
||
|
int ItemsCount = (int)(Size / ItemSize);
|
||
|
|
||
|
for (int Index = 0; Index < ItemsCount; Index++)
|
||
|
{
|
||
|
Items.AddLast(Pa);
|
||
|
|
||
|
Pa += ItemSize;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public bool TryGetItem(out ulong Pa)
|
||
|
{
|
||
|
lock (Items)
|
||
|
{
|
||
|
if (Items.First != null)
|
||
|
{
|
||
|
Pa = Items.First.Value;
|
||
|
|
||
|
Items.RemoveFirst();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Pa = 0;
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public void Free(ulong Pa)
|
||
|
{
|
||
|
lock (Items)
|
||
|
{
|
||
|
Items.AddFirst(Pa);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|