A high-performance, non-blocking MPMC (Multi-Producer Multi-Consumer) ring buffer for generic reference types.
Uses the Vyukov/Dmitry bounded MPMC queue algorithm with a parallel sequence buffer. Each slot in the sequence buffer carries a stamp that indicates whether the slot is available for writing (stamp == expected producer index) or reading (stamp == expected consumer index + 1). Both producerIndex and consumerIndex are advanced via CAS, allowing any number of threads to call offer and poll concurrently.
Thread safety: Fully thread-safe for any combination of concurrent producers and consumers. No external synchronization is required.
Null elements are not permitted. offer(null) throws NullPointerException.
Value parameters
- capacity
-
the buffer capacity, must be a power of two >= 2 (the sequence buffer algorithm requires at least 2 slots to distinguish written from consumed)
Attributes
- Companion
- object
- Source
- MpmcRingBuffer.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Returns true if the buffer contains no elements (approximate under concurrency).
Returns true if the buffer contains no elements (approximate under concurrency).
Attributes
- Source
- MpmcRingBuffer.scala
Returns true if the buffer is full (approximate under concurrency).
Returns true if the buffer is full (approximate under concurrency).
Attributes
- Source
- MpmcRingBuffer.scala
Tries to insert an element into the buffer without blocking.
Tries to insert an element into the buffer without blocking.
Multiple threads may call this method concurrently. The method uses a CAS loop on producerIndex and sequence stamps to coordinate between producers.
Value parameters
- a
-
the element to insert; must not be
null
Attributes
- Returns
-
trueif the element was successfully inserted,falseif the buffer is full - Throws
-
java.lang.NullPointerException
if the element is
null - Source
- MpmcRingBuffer.scala
Returns the number of elements currently in the buffer (approximate under concurrency).
Returns the number of elements currently in the buffer (approximate under concurrency).
Attributes
- Source
- MpmcRingBuffer.scala
Tries to remove an element from the buffer without blocking.
Tries to remove an element from the buffer without blocking.
Multiple threads may call this method concurrently. The method uses a CAS loop on consumerIndex and sequence stamps to coordinate between consumers.
Attributes
- Returns
-
the element, or
nullif the buffer is empty - Source
- MpmcRingBuffer.scala
Concrete fields
Attributes
- Source
- MpmcRingBuffer.scala
Inherited fields
Attributes
- Inherited from:
- MpmcConsumerFields (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad0 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad1 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcPad2 (hidden)
- Source
- MpmcRingBuffer.scala
Attributes
- Inherited from:
- MpmcProducerFields (hidden)
- Source
- MpmcRingBuffer.scala