/// <inheritdoc />
        public IReservoirSnapshot GetSnapshot(bool resetReservoir)
        {
            var lockTaken = false;

            Logger.Trace("Getting {Reservoir} snapshot", this);

            try
            {
                _lock.Enter(ref lockTaken);

                Logger.Trace("Lock entered for {Reservoir} snapshot", this);

                var snapshot = new WeightedSnapshot(_count.GetValue(), _sum.GetValue(), _values.Values);
                if (resetReservoir)
                {
                    ResetReservoir();
                }

                return(snapshot);
            }
            finally
            {
                if (lockTaken)
                {
                    _lock.Exit();
                    Logger.Trace("Lock exited after getting {Reservoir} snapshot", this);
                }

                Logger.Trace("Retrieved {Reservoir} snapshot", this);
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public IReservoirSnapshot GetSnapshot(bool resetReservoir)
        {
            var lockTaken = false;

            try
            {
                _lock.Enter(ref lockTaken);
                var snapshot = new WeightedSnapshot(_count.GetValue(), _sum.GetValue(), _values.Values);
                if (resetReservoir)
                {
                    ResetReservoir();
                }

                return(snapshot);
            }
            finally
            {
                if (lockTaken)
                {
                    _lock.Exit();
                }
            }
        }