TARAXA
taraxa::network::threadpool::PacketsThreadPool Class Reference

PacketsThreadPool for concurrent packets processing. More...

#include <tarcap_thread_pool.hpp>

Collaboration diagram for taraxa::network::threadpool::PacketsThreadPool:

Public Member Functions

 PacketsThreadPool (size_t workers_num=10, const addr_t &node_addr={})
 
 ~PacketsThreadPool ()
 
 PacketsThreadPool (const PacketsThreadPool &)=delete
 
PacketsThreadPooloperator= (const PacketsThreadPool &)=delete
 
 PacketsThreadPool (PacketsThreadPool &&)=delete
 
PacketsThreadPooloperator= (PacketsThreadPool &&)=delete
 
std::optional< uint64_t > push (std::pair< tarcap::TarcapVersion, PacketData > &&packet_data)
 Push the given element value to the end of the queue. Used for r-values. More...
 
void startProcessing ()
 Start all processing threads. More...
 
void stopProcessing ()
 Stop all processing threads. More...
 
void processPacket (size_t worker_id)
 Threadpool sycnchronized processing function, which internally calls packet-specific handlers. More...
 
void setPacketsHandlers (tarcap::TarcapVersion tarcap_version, std::shared_ptr< tarcap::PacketsHandler > packets_handlers)
 Sets packet handler. More...
 
std::tuple< size_t, size_t, size_t > getQueueSize () const
 Returns actual size of all priority queues (thread-safe) More...
 

Private Attributes

LOG_OBJECTS_DEFINE const size_t workers_num_
 
std::unordered_map< tarcap::TarcapVersion, std::shared_ptr< tarcap::PacketsHandler > > packets_handlers_
 
std::atomic< bool > stopProcessing_ {false}
 
uint64_t packets_count_ {0}
 
PriorityQueue queue_
 
std::mutex queue_mutex_
 
std::condition_variable cond_var_
 
std::vector< std::thread > workers_
 

Detailed Description

PacketsThreadPool for concurrent packets processing.

Constructor & Destructor Documentation

◆ PacketsThreadPool() [1/3]

taraxa::network::threadpool::PacketsThreadPool::PacketsThreadPool ( size_t  workers_num = 10,
const addr_t node_addr = {} 
)
Parameters
workers_numNumber of workers

◆ ~PacketsThreadPool()

taraxa::network::threadpool::PacketsThreadPool::~PacketsThreadPool ( )

◆ PacketsThreadPool() [2/3]

taraxa::network::threadpool::PacketsThreadPool::PacketsThreadPool ( const PacketsThreadPool )
delete

◆ PacketsThreadPool() [3/3]

taraxa::network::threadpool::PacketsThreadPool::PacketsThreadPool ( PacketsThreadPool &&  )
delete

Member Function Documentation

◆ getQueueSize()

std::tuple< size_t, size_t, size_t > taraxa::network::threadpool::PacketsThreadPool::getQueueSize ( ) const

Returns actual size of all priority queues (thread-safe)

Returns
std::tuple<size_t, size_t, size_t> - > std::tuple<HighPriorityQueue.size(), MidPriorityQueue.size(), LowPriorityQueue.size()>

◆ operator=() [1/2]

PacketsThreadPool& taraxa::network::threadpool::PacketsThreadPool::operator= ( const PacketsThreadPool )
delete

◆ operator=() [2/2]

PacketsThreadPool& taraxa::network::threadpool::PacketsThreadPool::operator= ( PacketsThreadPool &&  )
delete

◆ processPacket()

void taraxa::network::threadpool::PacketsThreadPool::processPacket ( size_t  worker_id)

Threadpool sycnchronized processing function, which internally calls packet-specific handlers.

Threadpool sycnchronized processing function, which calls user-defined custom processing function.

◆ push()

std::optional< uint64_t > taraxa::network::threadpool::PacketsThreadPool::push ( std::pair< tarcap::TarcapVersion, PacketData > &&  packet_data)

Push the given element value to the end of the queue. Used for r-values.

Pushes the given element value to the end of the queue. Used for r-values.

Returns
packet unique ID. In case push was not successful, empty optional is returned

◆ setPacketsHandlers()

void taraxa::network::threadpool::PacketsThreadPool::setPacketsHandlers ( tarcap::TarcapVersion  tarcap_version,
std::shared_ptr< tarcap::PacketsHandler packets_handlers 
)

Sets packet handler.

Parameters
packets_handlers

◆ startProcessing()

void taraxa::network::threadpool::PacketsThreadPool::startProcessing ( )

Start all processing threads.

◆ stopProcessing()

void taraxa::network::threadpool::PacketsThreadPool::stopProcessing ( )

Stop all processing threads.

Member Data Documentation

◆ cond_var_

std::condition_variable taraxa::network::threadpool::PacketsThreadPool::cond_var_
private

◆ packets_count_

uint64_t taraxa::network::threadpool::PacketsThreadPool::packets_count_ {0}
private

◆ packets_handlers_

std::unordered_map<tarcap::TarcapVersion, std::shared_ptr<tarcap::PacketsHandler> > taraxa::network::threadpool::PacketsThreadPool::packets_handlers_
private

◆ queue_

PriorityQueue taraxa::network::threadpool::PacketsThreadPool::queue_
private

◆ queue_mutex_

std::mutex taraxa::network::threadpool::PacketsThreadPool::queue_mutex_
private

◆ stopProcessing_

std::atomic<bool> taraxa::network::threadpool::PacketsThreadPool::stopProcessing_ {false}
private

◆ workers_

std::vector<std::thread> taraxa::network::threadpool::PacketsThreadPool::workers_
private

◆ workers_num_

LOG_OBJECTS_DEFINE const size_t taraxa::network::threadpool::PacketsThreadPool::workers_num_
private

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