aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Translation/TranslatedFunction.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure/Translation/TranslatedFunction.cs')
-rw-r--r--ARMeilleure/Translation/TranslatedFunction.cs31
1 files changed, 11 insertions, 20 deletions
diff --git a/ARMeilleure/Translation/TranslatedFunction.cs b/ARMeilleure/Translation/TranslatedFunction.cs
index f1dc6dee..36fae50a 100644
--- a/ARMeilleure/Translation/TranslatedFunction.cs
+++ b/ARMeilleure/Translation/TranslatedFunction.cs
@@ -4,22 +4,23 @@ using System.Threading;
namespace ARMeilleure.Translation
{
- class TranslatedFunction
+ sealed class TranslatedFunction
{
private const int MinCallsForRejit = 100;
- private GuestFunction _func;
- private IntPtr _funcPtr;
+ private readonly GuestFunction _func; // Ensure that this delegate will not be garbage collected.
- private bool _rejit;
- private int _callCount;
+ private int _callCount = 0;
- public bool HighCq => !_rejit;
+ public bool HighCq { get; }
+ public IntPtr FuncPtr { get; }
- public TranslatedFunction(GuestFunction func, bool rejit)
+ public TranslatedFunction(GuestFunction func, bool highCq)
{
- _func = func;
- _rejit = rejit;
+ _func = func;
+
+ HighCq = highCq;
+ FuncPtr = Marshal.GetFunctionPointerForDelegate<GuestFunction>(func);
}
public ulong Execute(State.ExecutionContext context)
@@ -29,17 +30,7 @@ namespace ARMeilleure.Translation
public bool ShouldRejit()
{
- return _rejit && Interlocked.Increment(ref _callCount) == MinCallsForRejit;
- }
-
- public IntPtr GetPointer()
- {
- if (_funcPtr == IntPtr.Zero)
- {
- _funcPtr = Marshal.GetFunctionPointerForDelegate(_func);
- }
-
- return _funcPtr;
+ return !HighCq && Interlocked.Increment(ref _callCount) == MinCallsForRejit;
}
}
} \ No newline at end of file