Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the deadline (in milliseconds) for when a given counter id may be reused.
        /// </summary>
        /// <param name="counterId"> to be read. </param>
        /// <returns> deadline (in milliseconds) for when a given counter id may be reused or <seealso cref="NOT_FREE_TO_REUSE"/> if
        /// currently in use. </returns>
        public long GetFreeForReuseDeadline(int counterId)
        {
            ValidateCounterId(counterId);

            return(MetaDataBuffer.GetLongVolatile(MetaDataOffset(counterId) + FREE_FOR_REUSE_DEADLINE_OFFSET));
        }