Пример #1
0
        ///<summary>
        /// Serialise publishers in sequence and set cursor to latest available sequence.
        ///</summary>
        ///<param name="sequence">sequence to be applied</param>
        ///<param name="cursor">cursor to serialise against.</param>
        ///<param name="batchSize">batchSize of the sequence.</param>
        public void SerialisePublishing(long sequence, Sequence cursor, long batchSize)
        {
            var spinWait = default(SpinWait);

            while (sequence - cursor.Value > _pendingPublication.Length)
            {
                spinWait.SpinOnce();
            }

            long expectedSequence = sequence - batchSize;

            for (long pendingSequence = expectedSequence + 1; pendingSequence <= sequence; pendingSequence++)
            {
                _pendingPublication.WriteFullFence((int)pendingSequence & _pendingMask, pendingSequence);
            }

            if (cursor.Value != expectedSequence)
            {
                return;
            }

            long nextSequence = expectedSequence + 1;

            while (cursor.CompareAndSet(expectedSequence, nextSequence))
            {
                expectedSequence = nextSequence;
                nextSequence++;
                if (_pendingPublication.ReadFullFence((int)nextSequence & _pendingMask) != nextSequence)
                {
                    break;
                }
            }
        }
Пример #2
0
 public void WriteFullFenceChangesInitialValue()
 {
     _volatile.WriteFullFence(0, NewValue);
     Assert.AreEqual(NewValue, _volatile.ReadUnfenced(0));
 }