Beispiel #1
0
        private static TimestampGeneratorProperties PropertiesFromOptions(SamplesCounterClockOptions options)
        {
            if (options.HasFlag(SamplesCounterClockOptions.AdjustForOverflow))
            {
                if (options.HasFlag(SamplesCounterClockOptions.ForceMonotonic))
                {
                    return(TimestampGeneratorProperties.Monotonic);
                }

                return(TimestampGeneratorProperties.None);
            }

            return(TimestampGeneratorProperties.Monotonic
                   | TimestampGeneratorProperties.UniformlyDistributed);
        }
Beispiel #2
0
        public const long MaximumNumberOfSamples = 9007199254740991; // 2^53 - 1

        /// <summary>
        /// Initializes a new instance of <see cref="SamplesCounterClock"/>.
        /// </summary>
        /// <param name="samplingRate">Acquired samples sampling rate.</param>
        /// <param name="options">Options for this timestamp generator, these options also affect generator properties.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="samplingRate"/> is 0 or a negative number.
        /// </exception>
        /// <exception cref="HardwareException">
        /// If requested sampling rate <paramref name="samplingRate"/> is too high for this timestamp generator
        /// and required precision cannot be guaranteed. In this case inner <see cref="HardwareError"/> will
        /// have class <see cref="HardwareErrorClass.Unsupported"/>.
        /// </exception>
        public SamplesCounterClock(double samplingRate, SamplesCounterClockOptions options)
            : base(PropertiesFromOptions(options))
        {
            if (samplingRate <= 0)
            {
                throw new ArgumentOutOfRangeException("Sampling rate cannot be zero or negative.", "samplingRate");
            }

            _options = options;

            unchecked
            {
                _ticksPerSample = TimeSpan.TicksPerSecond / samplingRate;
                Error           = Math.Floor(_ticksPerSample) - _ticksPerSample;
            }

            EnsureCounterHasEnoughPrecision();
        }