IntSpscRingBuffer

zio.blocks.ringbuffer.IntSpscRingBuffer
See theIntSpscRingBuffer companion object
final class IntSpscRingBuffer(val capacity: Int)

High-performance non-blocking SPSC ring buffer specialized for Int.

Layout: a single Array[Long]. Each slot packs both the data and the occupancy/control signal into one 64-bit word:

  • bits 32..63: tag (0 = empty, 1 = data, 2 = done)
  • bits 0..31: the user's Int value (only meaningful when tag == 1)

This makes the slot's own value act as the FastFlow signal: every insert/remove is a single memory-ordered op on a single cache line. Zero is the empty marker because the array is zero-initialized; a stored value with a non-zero tag is always non-zero regardless of the Int payload (including 0, Int.MinValue, Int.MaxValue, etc.).

In-band "done" sentinel: producers can call offerDone() to insert an end-of-stream marker after the last data value. Consumers reading via pollPacked() receive EMPTY_PACKED for empty, DONE_PACKED for the sentinel, or a TAG_FULL | Int payload value for data. This removes the need for a separate control queue alongside the data queue.

SPSC: one producer thread, one consumer thread.

Value parameters

capacity

must be a positive power of two

Attributes

Companion
object
Source
IntSpscRingBuffer.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def isEmpty: Boolean

Attributes

Source
IntSpscRingBuffer.scala
def isFull: Boolean

Attributes

Source
IntSpscRingBuffer.scala
def offer(a: Int): Boolean

Attributes

Source
IntSpscRingBuffer.scala
def offerDone(): Boolean

Insert the in-band done sentinel. Returns false if the buffer is full; the caller is expected to retry until it succeeds.

Insert the in-band done sentinel. Returns false if the buffer is full; the caller is expected to retry until it succeeds.

Attributes

Source
IntSpscRingBuffer.scala
def peek(): Boolean

Attributes

Source
IntSpscRingBuffer.scala
def pollPacked(): Long

Atomically polls the next slot and returns the raw packed value:

Atomically polls the next slot and returns the raw packed value:

  • EMPTY_PACKED (0L) — slot is empty; consumer index is NOT advanced.
  • DONE_PACKED — in-band done sentinel; consumer index advanced.
  • any other value — packed data (TAG_FULL | (a & LOW32_MASK)); consumer index advanced. The payload is packed.toInt.

Attributes

Source
IntSpscRingBuffer.scala
def size: Int

Attributes

Source
IntSpscRingBuffer.scala
def take(): Int

Attributes

Source
IntSpscRingBuffer.scala

Concrete fields

val capacity: Int

Attributes

Source
IntSpscRingBuffer.scala

Inherited fields

var consumerIndex: Long

Attributes

Inherited from:
IntSpscConsumerFields (hidden)
Source
IntSpscRingBuffer.scala
var p00: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p01: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p02: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p03: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p04: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p05: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p06: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p07: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p08: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p09: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p0a: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p0b: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p0c: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p0d: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p0e: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p0f: Long

Attributes

Inherited from:
IntSpscPad0 (hidden)
Source
IntSpscRingBuffer.scala
var p10: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p11: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p12: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p13: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p14: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p15: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p16: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p17: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p18: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p19: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p1a: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p1b: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p1c: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p1d: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p1e: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p1f: Long

Attributes

Inherited from:
IntSpscPad1 (hidden)
Source
IntSpscRingBuffer.scala
var p20: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p21: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p22: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p23: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p24: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p25: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p26: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p27: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p28: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p29: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p2a: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p2b: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p2c: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p2d: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p2e: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var p2f: Long

Attributes

Inherited from:
IntSpscPad2 (hidden)
Source
IntSpscRingBuffer.scala
var producerIndex: Long

Attributes

Inherited from:
IntSpscProducerFields (hidden)
Source
IntSpscRingBuffer.scala
var producerLimit: Long

Attributes

Inherited from:
IntSpscProducerFields (hidden)
Source
IntSpscRingBuffer.scala