data.fifo


template <
    typename T,
    auto Size,
    bool EnqueueBlocking = true,
    bool DequeueBlocking = true
    >
class FIFO §

Basic FIFO.

Parameters

  • typename T
    

    Type for each entry of the FIFO.

  • auto Size
    

    Maximum number of entries that can be stored.

  • bool EnqueueBlocking = true
    

    Block on enqueue if the FIFO is full until an entry frees up. By default this is true. Otherwise, the caller must ensure that the FIFO is not full.

  • bool DequeueBlocking = true
    

    Block on dequeue if the FIFO is empty until an entry arrives. By default, this is true. Otherwise, the caller must ensure that the FIFO is not empty.

Methods

  • inline count_t<Size> count() §
    

    Return the number of elements that have been written and not read. Note that this can be out of date the instant its read due to other threads reading/writing to the FIFO. This cannot be used for checking empty/full for non-blocking versions of the FIFO.

  • T dequeue() §
    

    Read one entry from FIFO. Block if FIFO is empty and DequeueBlocking is true.

  • void enqueue(T value) §
    

    Write one entry to the FIFO. Block if FIFO is full and EnqueueBlocking is true.

Invariants

  • (0 == (Size & (Size - 1)))
    

    Size must be a power of 2.

template <typename T, auto Size, bool DequeueBlocking = true>
class FIFO_store_and_forward §

Store and forward FIFO.

Parameters

  • typename T
    

    Type for each entry of the FIFO.

  • auto Size
    

    Maximum number of entries that can be stored.

  • bool DequeueBlocking = true
    

    Block on dequeue if the FIFO is empty until an entry arrives. By default, this is true. Otherwise, the caller must ensure that the FIFO is not empty.

Methods

  • inline count_t<Size> count() §
    

    Return the number of elements that have been written and not read. Note that this can be out of date the instant its read due to other threads reading/writing to the FIFO. This cannot be used for checking empty/full for non-blocking versions of the FIFO.

  • T dequeue() §
    

    Read one entry from FIFO. Block if FIFO is empty and DequeueBlocking is true.

  • count_t<Size> enqueue(T value, bool releaseDeferredDequeues) §
    

    Write one entry to the FIFO. Block if FIFO is full. Return the number of dequeue calls that were released.

Invariants

  • (0 == (Size & (Size - 1)))
    

    Size must be a power of 2.

template <typename T, auto Size>
class fifo_nb §

A FIFO that enables polling read/write operations and conditionally reading an element based on the value of that element.

Parameters

  • typename T
    

    Type for each entry of the FIFO.

  • auto Size
    

    Maximum number of entries that can be stored.

Methods

  • inline bool full() §
    

    Return true if no more entries can be enqueued. Typical usage is to call full and reserve_enqueue in the same atomic block.

  • inline void reserve_enqueue() §
    

    Reserve one slot, so that data can be safely written into the FIFO at a future point in time. Typical usage is to call full and reserve_enqueue in the same atomic block. Each call to reserve_enqueue must be paired with 1 call to enqueue. The enqueue call does not need to be in an atomic block with the call to reserve_enqueue.

  • inline bool check_and_reserve() §
    

    Helper function that checks fifo state and conditionally reserves a slot. If the fifo is not full, then this reserves one slot and returns true. Return false otherwise.

  • void enqueue(T value) §
    

    Write one data item to the queue. reserve_enqueue must have been called previously.

  • void enqueue_blocking(T value) §
    

    Helper function that blocks the current thread until the output is not full and then enqueues one item.

  • inline bool empty() §
    

    Return true if there is no more data in the queue. Typical usage is to call empty in the same atomic block as front and pop.

  • inline T front() §
    

    Return the value at the head of the queue. Typical usage is to call empty in the same atomic block as front and pop.

  • inline void pop() §
    

    Remove 1 item from the queue. Typical usage is to call empty in the same atomic block as front and pop.

Invariants

  • (0 == (Size & (Size - 1)))
    

    Size must be a power of 2.