public void AddLast(Bucket o) { ListState currentState = state.Value; // create new version of state (what we want it to become) ListState 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>) */ if (state.CompareAndSet(currentState, newState)) { // we succeeded return; } 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 return; } }
public void AddLast(Bucket o) { ListState currentState = _state.Value; // create new version of state (what we want it to become) ListState 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 }