KSlabHeap.cs 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections.Generic;
  2. namespace Ryujinx.HLE.HOS.Kernel
  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. }