This library provides an implementation of a FIFO queue (aka Pipe) which can be used as a communication mechanism in multi-threaded applications. The producer thread can insert the data at one end of the pipe which can then be retrieved by the consumer thread at the other end of the pipe in FIFO order. Refer to the test case for an example instance.
- Include the header into you code.
- Create an object of the Pipe class.
- Pass this object to both the producer and the consumer threads by reference.
- Interact with the Pipe using the API call described below.
-
Pipe<T, n>(): Constructor for the pipe.Tis the data type for the pipe.nis the maximum queue length uptil which the transmit calls should not block. -
bool transmit_data(T&& data):
Inserts an element of typeTin the pipe. This is a blocking call.datais the data element to be transmitted. Returnstrueif the transmission was successfull,falseotherwise. Transmision will fail iffinish_transmission()was called before the call totransmit_data(T&& data). -
bool finish_transmission(): Closes the transmission end of the pipe. This is a non-blocking call. Returnstrueif the attempt to close the pipe was successfull,falseotherwise. Will return false iffinish_transmission()was already called once before this call. -
bool is_empty(): Returnstrueif the pipe is empty. This is a non-blocking call. -
std::optional<T> receive_data(): Retrieves an element of typeTfrom the pipe in First-In-First-Out order. This is a blocking call. Returns an optional value of typeT. The value is absent only if the pipe is empty and it has been closed.