CeilingNextPowerOfTwo() 공개 정적인 메소드

Calculate the next power of 2, greater than or equal to x.
public static CeilingNextPowerOfTwo ( this x ) : int
x this Value to round up
리턴 int
예제 #1
0
        /// <summary>
        /// Construct a RingBuffer with the full option set.
        /// </summary>
        /// <param name="entryFactory"> entryFactory to create instances of T for filling the RingBuffer</param>
        /// <param name="size">size of the RingBuffer that will be rounded up to the next power of 2</param>
        /// <param name="claimStrategyOption"> threading strategy for producers claiming entries in the ring.</param>
        /// <param name="waitStrategyOption">waiting strategy employed by consumers waiting on entries becoming available.</param>
        public RingBuffer(Func <T> entryFactory, int size, ClaimStrategyFactory.ClaimStrategyOption claimStrategyOption = ClaimStrategyFactory.ClaimStrategyOption.Multithreaded, WaitStrategyFactory.WaitStrategyOption waitStrategyOption = WaitStrategyFactory.WaitStrategyOption.Blocking)
        {
            _claimStrategyOption = claimStrategyOption;
            var sizeAsPowerOfTwo = Util.CeilingNextPowerOfTwo(size);

            _ringModMask = sizeAsPowerOfTwo - 1;
            _entries     = new Entry <T> [sizeAsPowerOfTwo];

            _claimStrategy = ClaimStrategyFactory.GetInstance(claimStrategyOption);
            _waitStrategy  = WaitStrategyFactory.GetInstance(waitStrategyOption);

            Fill(entryFactory);
        }
예제 #2
0
        public RingBuffer(IEntryFactory <T> entryFactory,
                          int size,
                          IClaimStrategy claimStrategyOption,
                          IWaitStrategy <T> waitStrategyOption)
        {
            int sizeAsPowerOfTwo = Util.CeilingNextPowerOfTwo(size);

            _ringModMask = sizeAsPowerOfTwo - 1;
            _entries     = new T[sizeAsPowerOfTwo];

            _entryFactory  = entryFactory;
            _claimStrategy = claimStrategyOption;
            _waitStrategy  = waitStrategyOption;

            Fill();
        }
예제 #3
0
        /// <summary>
        /// Construct a RingBuffer with the full option set.
        /// </summary>
        /// <param name="eventFactory">eventFactory to create entries for filling the RingBuffer</param>
        /// <param name="claimStrategy">threading strategy for publisher claiming entries in the ring.</param>
        /// <param name="waitStrategy">waiting strategy employed by processorsToTrack waiting on entries becoming available.</param>
        public RingBuffer(Func <T> eventFactory, IClaimStrategy claimStrategy, IWaitStrategy waitStrategy)
            : base(claimStrategy, waitStrategy)
        {
            if (Util.CeilingNextPowerOfTwo(claimStrategy.BufferSize) != claimStrategy.BufferSize)
            {
                throw new ArgumentException("bufferSize must be a power of 2");
            }

            _indexMask = claimStrategy.BufferSize - 1;
            _entries   = new T[claimStrategy.BufferSize];

            for (int i = 0; i < _entries.Length; i++)
            {
                _entries[i] = eventFactory();
            }
        }