BucketCircularArray.AddLast C# (CSharp) Method

AddLast() public method

public AddLast ( o ) : void
return void
            public void AddLast(Bucket o)
            {
                var currentState = _state.Value;

                // create new version of state (what we want it to become)
                var newState = currentState.AddBucket(o);

                /*
                 * use compareAndSet to set in case multiple threads are attempting (which shouldn't be the case because since addLast will ONLY be called by a single thread at a time due to protection
                 * provided in <code>getCurrentBucket</code>)
                 */
#pragma warning disable S3923 // All branches in a conditional structure should not have exactly the same implementation
                if (_state.CompareAndSet(currentState, newState))
                {
                    // we succeeded
                }
                else
                {
                    // we failed, someone else was adding or removing
                    // instead of trying again and risking multiple addLast concurrently (which shouldn't be the case)
                    // we'll just return and let the other thread 'win' and if the timing is off the next call to getCurrentBucket will fix things
                }
#pragma warning restore S3923 // All branches in a conditional structure should not have exactly the same implementation
            }