feat(headless): add deterministic multi-session scheduler
This commit is contained in:
parent
b299e3738e
commit
7e8acb74dd
6 changed files with 694 additions and 54 deletions
25
src/AcDream.Headless/Hosting/HeadlessMonotonicTime.cs
Normal file
25
src/AcDream.Headless/Hosting/HeadlessMonotonicTime.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
namespace AcDream.Headless.Hosting;
|
||||
|
||||
internal static class HeadlessMonotonicTime
|
||||
{
|
||||
internal static long Add(
|
||||
TimeProvider timeProvider,
|
||||
long timestamp,
|
||||
TimeSpan duration)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(timeProvider);
|
||||
if (duration < TimeSpan.Zero)
|
||||
throw new ArgumentOutOfRangeException(nameof(duration));
|
||||
|
||||
double ticks =
|
||||
duration.TotalSeconds * timeProvider.TimestampFrequency;
|
||||
if (!double.IsFinite(ticks) || ticks > long.MaxValue)
|
||||
return long.MaxValue;
|
||||
long delta = Math.Max(
|
||||
1L,
|
||||
checked((long)Math.Ceiling(ticks)));
|
||||
return timestamp > long.MaxValue - delta
|
||||
? long.MaxValue
|
||||
: timestamp + delta;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue