TARAXA
taraxa::network::threadpool::PriorityQueue Class Reference

#include <priority_queue.hpp>

Collaboration diagram for taraxa::network::threadpool::PriorityQueue:

Public Member Functions

 PriorityQueue (size_t tp_workers_count, const addr_t &node_addr={})
 
void pushBack (std::pair< tarcap::TarcapVersion, PacketData > &&packet)
 Pushes new packet into the priority queue. More...
 
std::optional< std::pair< tarcap::TarcapVersion, PacketData > > pop ()
 
bool empty () const
 
void updateDependenciesStart (const PacketData &packet)
 Updates blocking dependencies at the start of packet processing. More...
 
void updateDependenciesFinish (const PacketData &packet, std::mutex &queue_mutex, std::condition_variable &cond_var)
 Updates blocking dependencies after packet processing is done. More...
 
size_t getPrirotityQueueSize (PacketData::PacketPriority priority) const
 Returns specified priority queue actual size. More...
 
bool isNonBlockingPacket (SubprotocolPacketType packet_type) const
 
bool updateBlockingDependencies (const PacketData &packet, bool unblock_processing=false)
 Updates packet blocking dependency. More...
 

Private Member Functions

bool canBorrowThread ()
 Queue can borrow reserved thread from one of the other priority queues but each queue must have at least 1 thread reserved all the time even if has nothing to do. More...
 

Private Attributes

LOG_OBJECTS_DEFINE std::array< PacketsQueue, PacketData::PacketPriority::Count > packets_queues_
 
PacketsBlockingMask blocked_packets_mask_
 
const size_t MAX_TOTAL_WORKERS_COUNT
 
std::atomic< size_t > act_total_workers_count_
 

Constructor & Destructor Documentation

◆ PriorityQueue()

taraxa::network::threadpool::PriorityQueue::PriorityQueue ( size_t  tp_workers_count,
const addr_t node_addr = {} 
)

Member Function Documentation

◆ canBorrowThread()

bool taraxa::network::threadpool::PriorityQueue::canBorrowThread ( )
private

Queue can borrow reserved thread from one of the other priority queues but each queue must have at least 1 thread reserved all the time even if has nothing to do.

Returns
true if thread can be borrowed, otherwise false

◆ empty()

bool taraxa::network::threadpool::PriorityQueue::empty ( ) const
Returns
true of all priority packets_queues_ are empty, otheriwse false

◆ getPrirotityQueueSize()

size_t taraxa::network::threadpool::PriorityQueue::getPrirotityQueueSize ( PacketData::PacketPriority  priority) const

Returns specified priority queue actual size.

Parameters
priority
Returns
size_t

◆ isNonBlockingPacket()

bool taraxa::network::threadpool::PriorityQueue::isNonBlockingPacket ( SubprotocolPacketType  packet_type) const
Parameters
packet_type
Returns
true for non-blocking packet types, otherwise false

◆ pop()

std::optional< std::pair< tarcap::TarcapVersion, PacketData > > taraxa::network::threadpool::PriorityQueue::pop ( )
Returns
std::optional<PacketData> packet with the highest priority & oldest "receive" time

◆ pushBack()

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

Pushes new packet into the priority queue.

Parameters
packet

◆ updateBlockingDependencies()

bool taraxa::network::threadpool::PriorityQueue::updateBlockingDependencies ( const PacketData packet,
bool  unblock_processing = false 
)

Updates packet blocking dependency.

Parameters
packet
unblock_processingif true, unblock packet processing, otherwise block processing
Returns
true if blocking dependency for provided packet was updated, otherwise false

◆ updateDependenciesFinish()

void taraxa::network::threadpool::PriorityQueue::updateDependenciesFinish ( const PacketData packet,
std::mutex &  queue_mutex,
std::condition_variable &  cond_var 
)

Updates blocking dependencies after packet processing is done.

Parameters
packet
queue_mutex_must be locked if processing also blocking dependencies
cond_varnotify function is called if processing also blocking dependencies

◆ updateDependenciesStart()

void taraxa::network::threadpool::PriorityQueue::updateDependenciesStart ( const PacketData packet)

Updates blocking dependencies at the start of packet processing.

Parameters
packet

Member Data Documentation

◆ act_total_workers_count_

std::atomic<size_t> taraxa::network::threadpool::PriorityQueue::act_total_workers_count_
private

◆ blocked_packets_mask_

PacketsBlockingMask taraxa::network::threadpool::PriorityQueue::blocked_packets_mask_
private

◆ MAX_TOTAL_WORKERS_COUNT

const size_t taraxa::network::threadpool::PriorityQueue::MAX_TOTAL_WORKERS_COUNT
private

◆ packets_queues_

LOG_OBJECTS_DEFINE std::array<PacketsQueue, PacketData::PacketPriority::Count> taraxa::network::threadpool::PriorityQueue::packets_queues_
private
Initial value:
{PacketsQueue(), PacketsQueue(),
PacketsQueue()}

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