示例#1
0
        public void Can_get_and_increment()
        {
            _num.SetValue(10L);

            _num.GetAndIncrement().Should().Be(10L);
            _num.GetValue().Should().Be(11L);

            _num.GetAndIncrement(5L).Should().Be(11L);
            _num.GetValue().Should().Be(16L);
        }
示例#2
0
 /// <summary>
 ///     Indicate exit from a critical section containing a write operation.
 ///     This call is wait-free on architectures that support wait free atomic increment operations,
 ///     and is lock-free on architectures that do not.
 ///     {@link WriterReaderPhaser#writerCriticalSectionExit(long)} must be matched with a preceding
 ///     {@link WriterReaderPhaser#writerCriticalSectionEnter()} call, and must be provided with the
 ///     matching {@link WriterReaderPhaser#writerCriticalSectionEnter()} call's return value, in
 ///     order for CriticalSectionPhaser synchronization to function properly.
 /// </summary>
 /// <param name="criticalValueAtEnter">
 ///     the (opaque) value returned from the matching {@link
 ///     WriterReaderPhaser#writerCriticalSectionEnter()} call.
 /// </param>
 public void WriterCriticalSectionExit(long criticalValueAtEnter)
 {
     if (criticalValueAtEnter < 0)
     {
         oddEndEpoch.GetAndIncrement();
     }
     else
     {
         evenEndEpoch.GetAndIncrement();
     }
 }
示例#3
0
 /// <summary>
 ///     Indicate entry to a critical section containing a write operation.
 ///     This call is wait-free on architectures that support wait free atomic increment operations,
 ///     and is lock-free on architectures that do not.
 ///     {@link WriterReaderPhaser#writerCriticalSectionEnter()} must be matched with a subsequent
 ///     {@link WriterReaderPhaser#writerCriticalSectionExit(long)} in order for CriticalSectionPhaser
 ///     synchronization to function properly.
 /// </summary>
 /// <returns>
 ///     an (opaque) value associated with the critical section entry, which MUST be provided to the matching {@link
 ///     WriterReaderPhaser#writerCriticalSectionExit} call.
 /// </returns>
 public long WriterCriticalSectionEnter()
 {
     return(startEpoch.GetAndIncrement());
 }