Add PPTC support

This commit is contained in:
FICTURE7 2021-04-09 20:55:24 +04:00
parent 1803b9fef9
commit 4478a32114
4 changed files with 44 additions and 33 deletions

View file

@ -1,24 +1,22 @@
using ARMeilleure.Common;
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace ARMeilleure.Translation
{
class TranslatedFunction
{
private const int MinCallsForRejit = 100;
private readonly GuestFunction _func; // Ensure that this delegate will not be garbage collected.
private int _callCount;
public Counter CallCounter { get; }
public ulong GuestSize { get; }
public bool HighCq { get; }
public IntPtr FuncPtr { get; }
public TranslatedFunction(GuestFunction func, ulong guestSize, bool highCq)
public TranslatedFunction(GuestFunction func, Counter callCounter, ulong guestSize, bool highCq)
{
_func = func;
CallCounter = callCounter;
GuestSize = guestSize;
HighCq = highCq;
FuncPtr = Marshal.GetFunctionPointerForDelegate(func);
@ -28,15 +26,5 @@ namespace ARMeilleure.Translation
{
return _func(context.NativeContextPtr);
}
public bool ShouldRejit()
{
return !HighCq && Interlocked.Increment(ref _callCount) == MinCallsForRejit;
}
public void ResetCallCount()
{
Interlocked.Exchange(ref _callCount, 0);
}
}
}