VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::MultiLoop Class Reference

Multi-threaded variant of MessageLoop running tasks on a worker-thread pool. More...

#include <multi_loop.h>

Inheritance diagram for vlink::MultiLoop:
Collaboration diagram for vlink::MultiLoop:

Public Member Functions

 MultiLoop (size_t thread_num=4U)
 Constructs a MultiLoop with the default kNormalType queue and thread_num workers.
 MultiLoop (size_t thread_num, Type type)
 Constructs a MultiLoop with a specific queue type.
 ~MultiLoop () override
 Destructor. Quits the loop and joins all worker threads.
bool is_in_same_thread () const override
 Returns true if the calling thread is one of the worker threads.

Protected Member Functions

void on_begin () override
 Called once on each worker thread immediately after it starts.
void on_end () override
 Called once on each worker thread just before it exits.
void on_task_changed (Callback &&callback, uint32_t start_time) override
 Called on the worker thread executing the task, before the task runs.

Additional Inherited Members

 Queue implementation type. More...
 Idle strategy controlling CPU and latency trade-offs. More...
 Pre-defined task priority levels for kPriorityType loops. More...

Detailed Description

Multi-threaded variant of MessageLoop running tasks on a worker-thread pool.

All threads share the same task queue. Tasks are not guaranteed to execute in order.

Constructor & Destructor Documentation

◆ MultiLoop() [1/2]

vlink::MultiLoop::MultiLoop ( size_t thread_num = 4U)
explicit

Constructs a MultiLoop with the default kNormalType queue and thread_num workers.

Parameters
thread_numNumber of worker threads. Default: 4.
Here is the caller graph for this function:

◆ MultiLoop() [2/2]

vlink::MultiLoop::MultiLoop ( size_t thread_num,
Type type )
explicit

Constructs a MultiLoop with a specific queue type.

Parameters
thread_numNumber of worker threads.
typeQueue implementation type (see MessageLoop::Type).

◆ ~MultiLoop()

vlink::MultiLoop::~MultiLoop ( )
override

Destructor. Quits the loop and joins all worker threads.

Member Function Documentation

◆ is_in_same_thread()

bool vlink::MultiLoop::is_in_same_thread ( ) const
nodiscardoverridevirtual

Returns true if the calling thread is one of the worker threads.

Returns
true if called from any thread owned by this MultiLoop.

Reimplemented from vlink::MessageLoop.

◆ on_begin()

void vlink::MultiLoop::on_begin ( )
overrideprotectedvirtual

Called once on each worker thread immediately after it starts.

Override to perform per-thread initialisation (e.g., setting thread name or affinity).

Reimplemented from vlink::MessageLoop.

◆ on_end()

void vlink::MultiLoop::on_end ( )
overrideprotectedvirtual

Called once on each worker thread just before it exits.

Override to perform per-thread cleanup.

Reimplemented from vlink::MessageLoop.

◆ on_task_changed()

void vlink::MultiLoop::on_task_changed ( Callback && callback,
uint32_t start_time )
overrideprotectedvirtual

Called on the worker thread executing the task, before the task runs.

Parameters
callbackThe task about to be executed.
start_timeMillisecond timestamp at which the task was dequeued.

Reimplemented from vlink::MessageLoop.

Here is the call graph for this function:

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