Struct anira::SessionElement::ThreadSafeStruct

struct ThreadSafeStruct

Collaboration diagram for anira::SessionElement::ThreadSafeStruct:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="anira::Semaphore" tooltip="anira::Semaphore"]
    "1" [label="anira::SessionElement::ThreadSafeStruct" tooltip="anira::SessionElement::ThreadSafeStruct" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=forward tooltip="usage"]
}

Thread-safe data structure for concurrent inference processing.

This nested structure provides thread-safe coordination between the audio thread and inference threads. Each structure can hold one inference request and includes synchronization primitives to ensure safe concurrent access.

The structure uses atomic operations and semaphores to coordinate:

  • Availability checking (m_free)

  • Completion notification (m_done_semaphore, m_done_atomic)

  • Data integrity during concurrent access

  • Timestamping for latency tracking

Public Functions

ThreadSafeStruct(const std::vector<size_t> &tensor_input_size, const std::vector<size_t> &tensor_output_size)

Constructor that initializes thread-safe structure with tensor dimensions.

Creates buffers for input and output tensors with the specified sizes and initializes synchronization primitives.

Parameters:
  • tensor_input_size – Vector of input tensor sizes

  • tensor_output_size – Vector of output tensor sizes

Public Members

std::atomic<bool> m_free = {true}

Atomic flag indicating if this structure is available for use

anira::Semaphore m_done_semaphore = {0}

Semaphore for blocking wait on inference completion

std::atomic<bool> m_done_atomic = {false}

Atomic flag for non-blocking completion checking

unsigned long m_time_stamp

Timestamp for latency tracking and debugging.

std::vector<BufferF> m_tensor_input_data

Input tensor data buffers.

std::vector<BufferF> m_tensor_output_data

Output tensor data buffers.