OpenStory.Common.AtomicBoolean.FlipIf C# (CSharp) Method

FlipIf() public method

Flips the value of the AtomicBoolean if it is equal to the specified boolean value.
public FlipIf ( bool comparand ) : bool
comparand bool The value to compare with.
return bool
        public bool FlipIf(bool comparand)
        {
            int comparandAsInt = Convert.ToInt32(comparand);
            int newValueAsInt = Convert.ToInt32(!comparand);
            int originalValueAsInt = Interlocked.CompareExchange(ref this.value, newValueAsInt, comparandAsInt);

            return originalValueAsInt == comparandAsInt;
        }

Usage Example

Exemplo n.º 1
0
        public void FlipIf_Should_Return_False_When_Flip_Is_Not_Successful()
        {
            var b = new AtomicBoolean(true);

            var flipped = b.FlipIf(false);

            flipped.Should().BeFalse();
        }
All Usage Examples Of OpenStory.Common.AtomicBoolean::FlipIf