TARAXA
taraxa::network::threadpool::PacketsQueue Class Reference

#include <packets_queue.hpp>

Collaboration diagram for taraxa::network::threadpool::PacketsQueue:

Public Member Functions

 PacketsQueue ()=default
 
void pushBack (std::pair< tarcap::TarcapVersion, PacketData > &&packet)
 Push new task to the queue. More...
 
std::optional< std::pair< tarcap::TarcapVersion, PacketData > > pop (const PacketsBlockingMask &packets_blocking_mask)
 Return Task from queue. In some rare situations when all packets are blocked for processing due to blocking dependencies there might returned empty optional. More...
 
bool maxWorkersCountReached () const
 
void setMaxWorkersCount (size_t max_workers_count)
 Set new max workers count. More...
 
void incrementActWorkersCount ()
 Increment act_workers_count_ by 1. More...
 
void decrementActWorkersCount ()
 Decrement act_workers_count_ by 1. More...
 
bool empty () const
 
size_t size () const
 
size_t getActiveWorkersNum () const
 

Private Attributes

std::list< std::pair< tarcap::TarcapVersion, PacketData > > packets_
 
size_t kMaxWorkersCount_ {0}
 
std::atomic< size_t > act_workers_count_ {0}
 
std::atomic< size_t > act_packets_count_ {0}
 

Constructor & Destructor Documentation

◆ PacketsQueue()

taraxa::network::threadpool::PacketsQueue::PacketsQueue ( )
default

Member Function Documentation

◆ decrementActWorkersCount()

void taraxa::network::threadpool::PacketsQueue::decrementActWorkersCount ( )

Decrement act_workers_count_ by 1.

◆ empty()

bool taraxa::network::threadpool::PacketsQueue::empty ( ) const
Note
This method is thread-safe
Returns
true if queue is empty, otherwise false

◆ getActiveWorkersNum()

size_t taraxa::network::threadpool::PacketsQueue::getActiveWorkersNum ( ) const
Note
This method is thread-safe
Returns
number of workers that are currently processing packets from this queue

◆ incrementActWorkersCount()

void taraxa::network::threadpool::PacketsQueue::incrementActWorkersCount ( )

Increment act_workers_count_ by 1.

◆ maxWorkersCountReached()

bool taraxa::network::threadpool::PacketsQueue::maxWorkersCountReached ( ) const
Returns
false in case there is already kMaxWorkersCount_ workers processing packets from this queue at the same time, otherwise true

◆ pop()

std::optional< std::pair< tarcap::TarcapVersion, PacketData > > taraxa::network::threadpool::PacketsQueue::pop ( const PacketsBlockingMask packets_blocking_mask)

Return Task from queue. In some rare situations when all packets are blocked for processing due to blocking dependencies there might returned empty optional.

Note
If empty optional is returned too often, there might be some logical bug in terms of packet priority & existing dependencies
Parameters
blocked_packets_types_maskbit mask with all blocked packets for processing
Returns
std::optional<Task>

◆ pushBack()

void taraxa::network::threadpool::PacketsQueue::pushBack ( std::pair< tarcap::TarcapVersion, PacketData > &&  packet)

Push new task to the queue.

Parameters
packet

◆ setMaxWorkersCount()

void taraxa::network::threadpool::PacketsQueue::setMaxWorkersCount ( size_t  max_workers_count)

Set new max workers count.

Parameters
max_workers_count

◆ size()

size_t taraxa::network::threadpool::PacketsQueue::size ( ) const
Note
This method is thread-safe
Returns
size of the queue

Member Data Documentation

◆ act_packets_count_

std::atomic<size_t> taraxa::network::threadpool::PacketsQueue::act_packets_count_ {0}
private

◆ act_workers_count_

std::atomic<size_t> taraxa::network::threadpool::PacketsQueue::act_workers_count_ {0}
private

◆ kMaxWorkersCount_

size_t taraxa::network::threadpool::PacketsQueue::kMaxWorkersCount_ {0}
private

◆ packets_

std::list<std::pair<tarcap::TarcapVersion, PacketData> > taraxa::network::threadpool::PacketsQueue::packets_
private

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