feat(headless): add deterministic multi-session scheduler

This commit is contained in:
Erik 2026-07-27 07:51:49 +02:00
parent b299e3738e
commit 7e8acb74dd
6 changed files with 694 additions and 54 deletions

View 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;
}
}