2.4.3.1 Setup

typedef struct ZixRingImpl ZixRing

A lock-free ring buffer.

Thread-safe (with a few noted exceptions) for a single reader and single writer, and realtime-safe on both ends.

uint32_t zix_ring_capacity(const ZixRing *ring)

Return the capacity (the total write space when empty).

This function returns a constant for any given ring, and may (but usually shouldn’t) be called anywhere.

void zix_ring_free(ZixRing *ring)

Destroy a ring.

This frees the ring structure and its buffer, discarding its contents.

ZixStatus zix_ring_mlock(ZixRing *ring)

Lock the ring data into physical memory.

This function is NOT thread safe or real-time safe, but it should be called after zix_ring_new() to lock all ring memory to avoid page faults while using the ring.

ZixRing *zix_ring_new(ZixAllocator *allocator, uint32_t size)

Create a new ring.

Parameters:
  • allocator – Allocator for the ring object and its array.

  • size – Minimum size of the ring in bytes (rounded up to a power of 2).

Note that one byte of the ring is reserved, so in order to be able to write n bytes to the ring at once, size must be n + 1.

void zix_ring_reset(ZixRing *ring)

Reset (empty) a ring.

This function is NOT thread-safe, it may only be called when there is no reader or writer.