TranslatedFunction.cs 673 B

123456789101112131415161718192021222324252627282930
  1. using System.Threading;
  2. namespace ARMeilleure.Translation
  3. {
  4. class TranslatedFunction
  5. {
  6. private const int MinCallsForRejit = 100;
  7. private GuestFunction _func;
  8. private bool _rejit;
  9. private int _callCount;
  10. public TranslatedFunction(GuestFunction func, bool rejit)
  11. {
  12. _func = func;
  13. _rejit = rejit;
  14. }
  15. public ulong Execute(State.ExecutionContext context)
  16. {
  17. return _func(context.NativeContextPtr);
  18. }
  19. public bool ShouldRejit()
  20. {
  21. return _rejit && Interlocked.Increment(ref _callCount) == MinCallsForRejit;
  22. }
  23. }
  24. }