Exemple #1
0
        private int NextCounterId()
        {
            if (_freeList.Count == 0)
            {
                return(++_idHighWaterMark);
            }

            var counterId = _freeList.Dequeue();

            ValuesBuffer.PutLongOrdered(CounterOffset(counterId), 0L);

            return(counterId);
        }
Exemple #2
0
        /// <summary>
        /// Iterate over the counters and provide the value and basic metadata.
        /// </summary>
        /// <param name="consumer"> for each allocated counter. </param>
        public void ForEach(CounterConsumer consumer)
        {
            int counterId = 0;

            for (int i = 0, capacity = MetaDataBuffer.Capacity; i < capacity; i += METADATA_LENGTH)
            {
                int recordStatus = MetaDataBuffer.GetIntVolatile(i);

                if (RECORD_ALLOCATED == recordStatus)
                {
                    consumer(ValuesBuffer.GetLongVolatile(CounterOffset(counterId)), counterId, LabelValue(i));
                }
                else if (RECORD_UNUSED == recordStatus)
                {
                    break;
                }

                counterId++;
            }
        }
Exemple #3
0
        private int NextCounterId()
        {
            long nowMs = _epochClock.Time();

            for (int i = 0, size = _freeList.Count; i < size; i++)
            {
                int counterId = _freeList[i];

                long deadlineMs = MetaDataBuffer.GetLongVolatile(MetaDataOffset(counterId) + FREE_FOR_REUSE_DEADLINE_OFFSET);

                if (nowMs >= deadlineMs)
                {
                    _freeList.Remove(i);
                    ValuesBuffer.PutLongOrdered(CounterOffset(counterId), 0L);

                    return(counterId);
                }
            }

            return(++_idHighWaterMark);
        }
Exemple #4
0
 /// <summary>
 /// Set an <seealso cref="AtomicCounter"/> value based on counterId.
 /// </summary>
 /// <param name="counterId"> to be set. </param>
 /// <param name="value">     to set for the counter. </param>
 public void SetCounterValue(int counterId, long value)
 {
     ValuesBuffer.PutLongOrdered(CounterOffset(counterId), value);
 }
            public override FloatDictionaryArray Build(MemoryAllocator allocator)
            {
                allocator = allocator ?? MemoryAllocator.Default.Value;

                return(new FloatDictionaryArray(IndicesBuffer.Length, ValuesBuffer.Length, IndicesBuffer.Build(allocator), ValuesBuffer.Build(allocator),
                                                ArrowBuffer.Empty));
            }
Exemple #6
0
        /// <summary>
        /// Get the value for a given counter id as a volatile read.
        /// </summary>
        /// <param name="counterId"> to be read. </param>
        /// <returns> the current value of the counter. </returns>
        public long GetCounterValue(int counterId)
        {
            ValidateCounterId(counterId);

            return(ValuesBuffer.GetLongVolatile(CounterOffset(counterId)));
        }