/** * Check the the buffer capacity is the correct size (a power of 2 + {@link RingBufferDescriptor#TrailerLength}). * * @param capacity to be checked. * @throws IllegalStateException if the buffer capacity is incorrect. */ ///<summary> /// Checks the buffer capacity /// </summary> public static void EnsureCapacity(IUnsafeBuffer buffer) { if ((buffer.Size - TrailerLength).IsPowerOfTwo() == false) { throw new ArgumentException("Size must be a positive power of 2 + TrailerLength, but size=" + buffer.Size); } }
public ManyToOneRingBuffer(IUnsafeBuffer buffer) { _buffer = buffer; EnsureCapacity(buffer); Capacity = buffer.Size - TrailerLength; _mask = Capacity - 1; MaximumMessageLength = Capacity / 8; _tail = buffer.GetAtomicLong(Capacity + TailPositionOffset); _headCache = buffer.GetAtomicLong(Capacity + HeadCachePositionOffset); _head = buffer.GetAtomicLong(Capacity + HeadPositionOffset); }
public void SetUp() { _buffer = Substitute.For <IUnsafeBuffer>(); _buffer.Size.Returns(TotalBufferLength); _buffer.GetAtomicLong(Arg.Any <long>()).Returns(ci => new AtomicLong((byte *)ci.Arg <long>())); _buffer.GetAtomicInt(Arg.Any <long>()).Returns(ci => new AtomicInt((byte *)ci.Arg <long>())); _atomicLong = Substitute.For <Mocks.IAtomicLong>(); Mocks.AtomicLong = _atomicLong; _atomicInt = Substitute.For <Mocks.IAtomicInt>(); Mocks.AtomicInt = _atomicInt; _ringBuffer = new ManyToOneRingBuffer(_buffer); }
public void SetUp() { _buffer = Substitute.For<IUnsafeBuffer>(); _buffer.Size.Returns(TotalBufferLength); _buffer.GetAtomicLong(Arg.Any<long>()).Returns(ci => new AtomicLong((byte*) ci.Arg<long>())); _buffer.GetAtomicInt(Arg.Any<long>()).Returns(ci => new AtomicInt((byte*) ci.Arg<long>())); _atomicLong = Substitute.For<Mocks.IAtomicLong>(); Mocks.AtomicLong = _atomicLong; _atomicInt = Substitute.For<Mocks.IAtomicInt>(); Mocks.AtomicInt = _atomicInt; _ringBuffer = new OneToOneRingBuffer(_buffer); }