MpmcRingBuffer

zio.blocks.ringbuffer.MpmcRingBuffer
See theMpmcRingBuffer companion object
final class MpmcRingBuffer[A <: AnyRef](val capacity: Int)

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
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def isEmpty: Boolean

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
def isFull: Boolean

Returns true if the buffer is full (approximate under concurrency).

Returns true if the buffer is full (approximate under concurrency).

Attributes

Source
MpmcRingBuffer.scala
def offer(a: A): Boolean

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

true if the element was successfully inserted, false if the buffer is full

Throws
java.lang.NullPointerException

if the element is null

Source
MpmcRingBuffer.scala
def size: Int

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
def take(): A

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 null if the buffer is empty

Source
MpmcRingBuffer.scala

Concrete fields

val capacity: Int

Attributes

Source
MpmcRingBuffer.scala

Inherited fields

var consumerIndex: Long

Attributes

Inherited from:
MpmcConsumerFields (hidden)
Source
MpmcRingBuffer.scala
var p00: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p01: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p02: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p03: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p04: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p05: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p06: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p07: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p08: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p09: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p0a: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p0b: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p0c: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p0d: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p0e: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p0f: Long

Attributes

Inherited from:
MpmcPad0 (hidden)
Source
MpmcRingBuffer.scala
var p10: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p11: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p12: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p13: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p14: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p15: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p16: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p17: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p18: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p19: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p1a: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p1b: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p1c: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p1d: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p1e: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p1f: Long

Attributes

Inherited from:
MpmcPad1 (hidden)
Source
MpmcRingBuffer.scala
var p20: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p21: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p22: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p23: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p24: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p25: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p26: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p27: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p28: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p29: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p2a: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p2b: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p2c: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p2d: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p2e: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var p2f: Long

Attributes

Inherited from:
MpmcPad2 (hidden)
Source
MpmcRingBuffer.scala
var producerIndex: Long

Attributes

Inherited from:
MpmcProducerFields (hidden)
Source
MpmcRingBuffer.scala