srs-control 0.2.2
Loading...
Searching...
No Matches
srs::BufferQueue Class Reference

Class to manage the production and consumption of LargeBuffer asynchronously. More...

#include <BufferQueue.hpp>

Collaboration diagram for srs::BufferQueue:

Classes

struct  Config
 Configuration for the buffer queue class. More...

Public Types

using Token = std::pair<moodycamel::ProducerToken, moodycamel::ConsumerToken>
 A queue token type used for enqueue and dequeue action. The token type consists of one producer token and one consumer token.

Public Member Functions

 BufferQueue (const Config &config)
 Default constructor.
void enqueue_empty (std::size_t bulk_size)
 Abort the blocking operation from BufferQueue::pop().
auto enqueue (LargeBuffer &element, Token &token) -> bool
 Try to first push a buffer into the valid buffer queue and then replace it with a buffer from the trash buffer queue.
void dequeue (LargeBuffer &element, Token &token)
 Blocking the current thread by first pushing the element to the trash buffer queue and then replacing it with a buffer from the valid buffer queue.
auto size () const -> auto
 Get the current size in the valid buffer queue.
auto capacity () const -> auto
 Get the current capacity of the buffer queue.
void register_report (AppReport &report)
auto get_config () const -> const auto &
 Getter of the config object.
auto get_producer_token () -> Token
 Get a queue token for a producer. The first value is the producer token for the valid_buffer_queue_ and the second value is the consumer token for the trash_buffer_queue_.
auto get_consumer_token () -> Token
 Get a queue token for a consumer. The first value is the producer token for the trash_buffer_queue_ and the second value is the consumer token for the valid_buffer_queue_.

Private Member Functions

void print_memory_pre_allocation ()

Private Attributes

Config config_
std::atomic< std::size_t > n_trash_recycle_empty_failures_ = 0
std::atomic< std::size_t > n_trash_recycle_full_failures_ = 0
std::atomic< std::size_t > n_valid_buffer_full_failures_ = 0
moodycamel::BlockingConcurrentQueue< LargeBuffer > valid_buffer_queue_
moodycamel::ConcurrentQueue< LargeBuffer > trash_buffer_queue_
moodycamel::ProducerToken internal_valid_buffer_token_ { valid_buffer_queue_ }
moodycamel::ProducerToken internal_trash_buffer_token_ { trash_buffer_queue_ }

Detailed Description

Class to manage the production and consumption of LargeBuffer asynchronously.

A BufferQueue contains two subqueues, implemented by the third party library. The first subqueue, called "valid_buffer_queue", stores the incoming buffer read the UDP socket, ready to be consumed by the analysis taskflow. The second subqueue, called "trash_buffer_queue" stores the already analyzed buffer from the taskflow, which can be given back to the UDP socket to read further UDP message.

Definition at line 22 of file BufferQueue.hpp.

Member Typedef Documentation

◆ Token

using srs::BufferQueue::Token = std::pair<moodycamel::ProducerToken, moodycamel::ConsumerToken>

A queue token type used for enqueue and dequeue action. The token type consists of one producer token and one consumer token.

Definition at line 41 of file BufferQueue.hpp.

Constructor & Destructor Documentation

◆ BufferQueue()

srs::BufferQueue::BufferQueue ( const Config & config)

Default constructor.

Parameters
configConfig object

Definition at line 16 of file BufferQueue.cpp.

Member Function Documentation

◆ capacity()

auto srs::BufferQueue::capacity ( ) const -> auto
inline

Get the current capacity of the buffer queue.

The capacity represents the maximum number of buffers that can be pushed to the valid buffer queue.

Returns
Capacity

Definition at line 90 of file BufferQueue.hpp.

◆ dequeue()

void srs::BufferQueue::dequeue ( LargeBuffer & element,
Token & token )

Blocking the current thread by first pushing the element to the trash buffer queue and then replacing it with a buffer from the valid buffer queue.

Parameters
elementThe buffer object to be pushed and replaced.

Definition at line 80 of file BufferQueue.cpp.

◆ enqueue()

auto srs::BufferQueue::enqueue ( LargeBuffer & element,
Token & token ) -> bool

Try to first push a buffer into the valid buffer queue and then replace it with a buffer from the trash buffer queue.

Parameters
elementThe buffer object to be pushed and replaced.
Returns
True if the pushing succeeds.

Definition at line 63 of file BufferQueue.cpp.

◆ enqueue_empty()

void srs::BufferQueue::enqueue_empty ( std::size_t bulk_size)

Abort the blocking operation from BufferQueue::pop().

See also
BufferQueue::pop

Definition at line 51 of file BufferQueue.cpp.

◆ get_config()

auto srs::BufferQueue::get_config ( ) const -> const auto &
inlinenodiscard

Getter of the config object.

Returns
Const reference to the config object.
See also
ref

Definition at line 100 of file BufferQueue.hpp.

◆ get_consumer_token()

auto srs::BufferQueue::get_consumer_token ( ) -> Token
inlinenodiscard

Get a queue token for a consumer. The first value is the producer token for the trash_buffer_queue_ and the second value is the consumer token for the valid_buffer_queue_.

Definition at line 116 of file BufferQueue.hpp.

◆ get_producer_token()

auto srs::BufferQueue::get_producer_token ( ) -> Token
inlinenodiscard

Get a queue token for a producer. The first value is the producer token for the valid_buffer_queue_ and the second value is the consumer token for the trash_buffer_queue_.

Definition at line 106 of file BufferQueue.hpp.

◆ print_memory_pre_allocation()

void srs::BufferQueue::print_memory_pre_allocation ( )
private

Definition at line 33 of file BufferQueue.cpp.

◆ register_report()

void srs::BufferQueue::register_report ( AppReport & report)

Definition at line 89 of file BufferQueue.cpp.

◆ size()

auto srs::BufferQueue::size ( ) const -> auto
inline

Get the current size in the valid buffer queue.

The size of the valid buffer queue means the number of buffers pushed to the queue.

Returns
Size of the buffer queue.

Definition at line 82 of file BufferQueue.hpp.

Member Data Documentation

◆ config_

Config srs::BufferQueue::config_
private

Definition at line 123 of file BufferQueue.hpp.

◆ internal_trash_buffer_token_

moodycamel::ProducerToken srs::BufferQueue::internal_trash_buffer_token_ { trash_buffer_queue_ }
private

Definition at line 130 of file BufferQueue.hpp.

◆ internal_valid_buffer_token_

moodycamel::ProducerToken srs::BufferQueue::internal_valid_buffer_token_ { valid_buffer_queue_ }
private

Definition at line 129 of file BufferQueue.hpp.

◆ n_trash_recycle_empty_failures_

std::atomic<std::size_t> srs::BufferQueue::n_trash_recycle_empty_failures_ = 0
private

Definition at line 124 of file BufferQueue.hpp.

◆ n_trash_recycle_full_failures_

std::atomic<std::size_t> srs::BufferQueue::n_trash_recycle_full_failures_ = 0
private

Definition at line 125 of file BufferQueue.hpp.

◆ n_valid_buffer_full_failures_

std::atomic<std::size_t> srs::BufferQueue::n_valid_buffer_full_failures_ = 0
private

Definition at line 126 of file BufferQueue.hpp.

◆ trash_buffer_queue_

moodycamel::ConcurrentQueue<LargeBuffer> srs::BufferQueue::trash_buffer_queue_
private

Definition at line 128 of file BufferQueue.hpp.

◆ valid_buffer_queue_

moodycamel::BlockingConcurrentQueue<LargeBuffer> srs::BufferQueue::valid_buffer_queue_
private

Definition at line 127 of file BufferQueue.hpp.


The documentation for this class was generated from the following files: