aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/KSlabHeap.cs
blob: 2d6b3ca0f7a6b6f18aaad5359175fed210323345 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
            }
        }
    }
}