TickSource.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Diagnostics;
  3. namespace Ryujinx.Cpu
  4. {
  5. public class TickSource : ITickSource
  6. {
  7. private static Stopwatch _tickCounter;
  8. private static double _hostTickFreq;
  9. /// <inheritdoc/>
  10. public ulong Frequency { get; }
  11. /// <inheritdoc/>
  12. public ulong Counter => (ulong)(ElapsedSeconds * Frequency);
  13. /// <inheritdoc/>
  14. public TimeSpan ElapsedTime => _tickCounter.Elapsed;
  15. /// <inheritdoc/>
  16. public double ElapsedSeconds => _tickCounter.ElapsedTicks * _hostTickFreq;
  17. public TickSource(ulong frequency)
  18. {
  19. Frequency = frequency;
  20. _hostTickFreq = 1.0 / Stopwatch.Frequency;
  21. _tickCounter = new Stopwatch();
  22. _tickCounter.Start();
  23. }
  24. /// <inheritdoc/>
  25. public void Suspend()
  26. {
  27. _tickCounter.Stop();
  28. }
  29. /// <inheritdoc/>
  30. public void Resume()
  31. {
  32. _tickCounter.Start();
  33. }
  34. }
  35. }