Esempio n. 1
0
        /// <summary>
        /// Registers occurrence (event).
        /// </summary>
        public void RegisterEvent()
        {
            var timepoint = StopwatchUtilities.GetTimestampAsTimeSpan();

            for (; ;)
            {
                ImmutableList <TimeSpan> newVersion;
                var originalVersion = itrlck.Get(ref _eventRiseTimepoints);
                //
                if (originalVersion.Count > __MaxBufferSize)
                {
                    originalVersion = P_Cleanup(timepoint);
                }
                //
                if (originalVersion.Count > 0)
                {
                    var upperBound = originalVersion.Count - 1;
                    newVersion = originalVersion;
                    for (var y = upperBound; y > -1; y--)
                    {
                        if (timepoint >= originalVersion[y])
                        {
                            if (y == upperBound)
                            {
                                newVersion = originalVersion.Add(value: timepoint);
                            }
                            else
                            {
                                newVersion = originalVersion.Insert(index: y, item: timepoint);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    newVersion = originalVersion.Add(timepoint);
                }
                //
                if (!ReferenceEquals(newVersion, originalVersion))
                {
                    if (ReferenceEquals(originalVersion, Interlocked.CompareExchange(ref _eventRiseTimepoints, value: newVersion, comparand: originalVersion)))
                    {
                        break;
                    }
                    else
                    {
                        Thread.Sleep(1);                         // Выполнение любого готового к выполнению потока в системе (ОС).
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets current rate (frequency) value.
        /// </summary>
        public int Frequency()
        {
            var nowTimepoint = StopwatchUtilities.GetTimestampAsTimeSpan();

            return(P_Cleanup(timepoint: nowTimepoint).Count);
        }