mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-09-12 02:38:50 +02:00
* add local var to reduce calling Marshal.GetFunctionPointerForDelegate * modify code style
45 lines
No EOL
1 KiB
C#
45 lines
No EOL
1 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading;
|
|
|
|
namespace ARMeilleure.Translation
|
|
{
|
|
class TranslatedFunction
|
|
{
|
|
private const int MinCallsForRejit = 100;
|
|
|
|
private GuestFunction _func;
|
|
private IntPtr _funcPtr;
|
|
|
|
private bool _rejit;
|
|
private int _callCount;
|
|
|
|
public bool HighCq => !_rejit;
|
|
|
|
public TranslatedFunction(GuestFunction func, bool rejit)
|
|
{
|
|
_func = func;
|
|
_rejit = rejit;
|
|
}
|
|
|
|
public ulong Execute(State.ExecutionContext context)
|
|
{
|
|
return _func(context.NativeContextPtr);
|
|
}
|
|
|
|
public bool ShouldRejit()
|
|
{
|
|
return _rejit && Interlocked.Increment(ref _callCount) == MinCallsForRejit;
|
|
}
|
|
|
|
public IntPtr GetPointer()
|
|
{
|
|
if (_funcPtr == IntPtr.Zero)
|
|
{
|
|
_funcPtr = Marshal.GetFunctionPointerForDelegate(_func);
|
|
}
|
|
|
|
return _funcPtr;
|
|
}
|
|
}
|
|
} |