reactor.util.concurrent.SpscLinkedArrayQueue Maven / Gradle / Ivy
Show all versions of redisson-all Show documentation
/*
* Copyright (c) 2016-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reactor.util.concurrent;
import java.util.AbstractQueue;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.BiPredicate;
import reactor.util.annotation.Nullable;
/**
* An unbounded, array-backed single-producer, single-consumer queue with a fixed link
* size.
*
* This implementation is based on JCTools' SPSC algorithms: SpscUnboundedArrayQueue
* and SpscUnboundedAtomicArrayQueue
* of which the {@code SpscUnboundedAtomicArrayQueue} was contributed by one of the
* authors of this library. The notable difference is that this class is not padded and
* there is no lookahead cache involved; padding has a toll on short lived or bursty uses
* and lookahead doesn't really matter with small queues.
*
* @param the value type
*/
final class SpscLinkedArrayQueue extends AbstractQueue
implements BiPredicate {
final int mask;
volatile long producerIndex;
@SuppressWarnings("rawtypes")
static final AtomicLongFieldUpdater PRODUCER_INDEX =
AtomicLongFieldUpdater.newUpdater(SpscLinkedArrayQueue.class,
"producerIndex");
AtomicReferenceArray