Class ReadyQueue

Class Documentation

class ReadyQueue

Public Functions

inline explicit ReadyQueue(unsigned num_workers)
auto pop() -> Reaction*

Retrieve a ready reaction from the queue.

This method may be called concurrently. In case the queue is empty, the method blocks and waits until a ready reaction becomes available.

void fill_up(std::vector<Reaction*> &ready_reactions)

Fill the queue up with ready reactions.

This method assumes that the internal queue is empty. It moves all reactions from the provided ready_reactions vector to the internal queue, leaving ready_reactions empty.

Note that this method is not thread-safe. The caller needs to ensure that no other thread will try to read from the queue during this operation.

Private Members

std::vector<Reaction*> queue_ = {}
std::atomic<std::ptrdiff_t> size_ = {0}
Semaphore sem_ = {0}
std::ptrdiff_t waiting_workers_ = {0}
const unsigned int num_workers_