1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
namespace Regorus
{
/// <summary>
/// Managed representation of the execution timer configuration used by the engine.
/// </summary>
public readonly struct ExecutionTimerConfig
{
/// <summary>
/// Initializes a new instance of the <see cref="ExecutionTimerConfig"/> struct.
/// </summary>
/// <param name="limit">Maximum wall-clock duration allowed for evaluation. Must be non-negative.</param>
/// <param name="checkInterval">Number of work units between timer checks. Must be non-zero.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="limit"/> is negative or <paramref name="checkInterval"/> is zero.</exception>
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;
}
/// <summary>
/// Maximum wall-clock duration allowed for an evaluation.
/// </summary>
public TimeSpan Limit { get; }
/// <summary>
/// Number of work units between timer checks.
/// </summary>
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,
};
}
}
}