KSlabHeap.cs 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections.Generic;
  2. namespace Ryujinx.HLE.HOS.Kernel.Memory
  3. {
  4. class KSlabHeap
  5. {
  6. private LinkedList<ulong> _items;
  7. public KSlabHeap(ulong pa, ulong itemSize, ulong size)
  8. {
  9. _items = new LinkedList<ulong>();
  10. int itemsCount = (int)(size / itemSize);
  11. for (int index = 0; index < itemsCount; index++)
  12. {
  13. _items.AddLast(pa);
  14. pa += itemSize;
  15. }
  16. }
  17. public bool TryGetItem(out ulong pa)
  18. {
  19. lock (_items)
  20. {
  21. if (_items.First != null)
  22. {
  23. pa = _items.First.Value;
  24. _items.RemoveFirst();
  25. return true;
  26. }
  27. }
  28. pa = 0;
  29. return false;
  30. }
  31. public void Free(ulong pa)
  32. {
  33. lock (_items)
  34. {
  35. _items.AddFirst(pa);
  36. }
  37. }
  38. }
  39. }