-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"cSpell.words": [ | ||
"Cloudtoid", | ||
"Diagnoser", | ||
"finalizer", | ||
"Interprocess", | ||
"Kaby", | ||
"Onnx", | ||
|
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,25 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Cloudtoid.Interprocess; | ||
|
||
// Inspired by https://github.com/dotnet/aspnetcore/blob/main/src/Shared/ValueStopwatch/ValueStopwatch.cs | ||
internal readonly struct ValueStopwatch | ||
{ | ||
private readonly long start; | ||
private ValueStopwatch(long start) => this.start = start; | ||
public readonly bool IsActive => start != 0; | ||
public static ValueStopwatch StartNew() => new(Stopwatch.GetTimestamp()); | ||
|
||
public readonly TimeSpan GetElapsedTime() | ||
{ | ||
// Start timestamp can't be zero in an initialized ValueStopwatch. It would have to be literally the first thing executed when the machine boots to be 0. | ||
// So it being 0 is a clear indication of default(ValueStopwatch) | ||
if (!IsActive) | ||
{ | ||
throw new InvalidOperationException( | ||
"An uninitialized, or 'default', ValueStopwatch cannot be used to get elapsed time."); | ||
} | ||
|
||
return Stopwatch.GetElapsedTime(start); | ||
} | ||
} |