-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #876 from kekekeks/monotonic-clock
Monotonic clock for #846
- Loading branch information
Showing
6 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Akka.Util | ||
{ | ||
internal static class MonotonicClock | ||
{ | ||
private static readonly Stopwatch Stopwatch = Stopwatch.StartNew(); | ||
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null; | ||
[DllImport("kernel32")] | ||
private static extern ulong GetTickCount64(); | ||
|
||
private const int TicksInMillisecond = 10000; | ||
|
||
public static TimeSpan Elapsed | ||
{ | ||
get | ||
{ | ||
return IsMono | ||
? Stopwatch.Elapsed | ||
: new TimeSpan((long) GetTickCount64()*TicksInMillisecond); | ||
} | ||
} | ||
|
||
public static TimeSpan ElapsedHighRes | ||
{ | ||
get { return Stopwatch.Elapsed; } | ||
} | ||
} | ||
} |