2.4.3.1 Setup — Zix 0.4.2 documentation

# 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.

ZixRing *zix_ring_new(ZixAllocator *allocator, uint32_t size)

  Create a new ring.

  Parameters:

    - allocator – Allocator for the ring object and its array.

    - size – Size of the ring in bytes (note this may be rounded up).

  At most `size` - 1 bytes may be stored in the ring at once.

void zix_ring_free(ZixRing *ring)

  Destroy a ring.

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.

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.

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.