// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; namespace Regorus { /// /// Managed representation of the execution timer configuration used by the engine. /// public readonly struct ExecutionTimerConfig { /// /// Initializes a new instance of the struct. /// /// Maximum wall-clock duration allowed for evaluation. Must be non-negative. /// Number of work units between timer checks. Must be non-zero. /// Thrown when is negative or is zero. public ExecutionTimerConfig(TimeSpan limit, uint checkInterval) { if (limit < TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(limit), "Execution timer limit must be non-negative."); } if (checkInterval == 0) { throw new ArgumentOutOfRangeException(nameof(checkInterval), "Execution timer check interval must be non-zero."); } Limit = limit; CheckInterval = checkInterval; } /// /// Maximum wall-clock duration allowed for an evaluation. /// public TimeSpan Limit { get; } /// /// Number of work units between timer checks. /// public uint CheckInterval { get; } internal Regorus.Internal.RegorusExecutionTimerConfig ToNative() { if (Limit < TimeSpan.Zero) { throw new InvalidOperationException("Execution timer limit must be non-negative."); } ulong ticks = checked((ulong)Limit.Ticks); ulong limitNanoseconds = checked(ticks * 100UL); return new Regorus.Internal.RegorusExecutionTimerConfig { limit_ns = limitNanoseconds, check_interval = CheckInterval, }; } } }