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
        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 #3
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);
 }