ryujinx/Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs
Alex Barney fb1d9493a3 Adjust naming conventions and general refactoring in HLE Project (#527)
* Rename enum fields

* Naming conventions

* Remove unneeded ".this"

* Remove unneeded semicolons

* Remove unused Usings

* Don't use var

* Remove unneeded enum underlying types

* Explicitly label class visibility

* Remove unneeded @ prefixes

* Remove unneeded commas

* Remove unneeded if expressions

* Method doesn't use unsafe code

* Remove unneeded casts

* Initialized objects don't need an empty constructor

* Remove settings from DotSettings

* Revert "Explicitly label class visibility"

This reverts commit ad5eb5787cc5b27a4631cd46ef5f551c4ae95e51.

* Small changes

* Revert external enum renaming

* Changes from feedback

* Apply previous refactorings to the merged code
2018-12-06 09:16:24 -02:00

60 lines
1.3 KiB
C#

using System;
namespace Ryujinx.HLE.HOS.Kernel
{
class KTlsPageManager
{
private const int TlsEntrySize = 0x200;
private long _pagePosition;
private int _usedSlots;
private bool[] _slots;
public bool IsEmpty => _usedSlots == 0;
public bool IsFull => _usedSlots == _slots.Length;
public KTlsPageManager(long pagePosition)
{
_pagePosition = pagePosition;
_slots = new bool[KMemoryManager.PageSize / TlsEntrySize];
}
public bool TryGetFreeTlsAddr(out long position)
{
position = _pagePosition;
for (int index = 0; index < _slots.Length; index++)
{
if (!_slots[index])
{
_slots[index] = true;
_usedSlots++;
return true;
}
position += TlsEntrySize;
}
position = 0;
return false;
}
public void FreeTlsSlot(int slot)
{
if ((uint)slot > _slots.Length)
{
throw new ArgumentOutOfRangeException(nameof(slot));
}
_slots[slot] = false;
_usedSlots--;
}
}
}