Class BatchBuffer
Defined in File batch_buffer.hpp
Class Documentation
-
class BatchBuffer
Object to synchronize batch results between threads.
Public Functions
-
BatchBuffer(const size_t n_threads, const size_t n_slots)
Constructor for the BatchBuffer object.
- Parameters:
n_threads – Amount of threads used in the specific run instance
n_slots – How many results to store for a single thread before blocking it
-
~BatchBuffer() = default
-
void cancel()
Cancel the buffer, unblocking all threads and preventing new samples from being added.
-
void addResults(const BatchResults &results, const size_t thread_id)
Add results to the buffer. Will throw if the buffer is full.
- Parameters:
results – The results to add
thread_id – The id of the thread that generated the results
-
std::optional<std::vector<BatchResults>> getResults()
Provides a BatchResult per thread, if available.
- Returns:
A vector with n_threads BatchResults, if available. Nullopt otherwise
-
void waitForSlotAvailable(const size_t thread_id) const
Wait for a slot to be available in the buffer.
- Parameters:
thread_id – The id of the thread that is waiting
-
BatchBuffer(const size_t n_threads, const size_t n_slots)