VLink  2.0.0
A high-performance communication middleware
vlink::MultiLoop Class Reference

MessageLoop subclass that forwards every task to an internal ThreadPool. 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. More...
 
 MultiLoop (size_t thread_num, Type type)
 Constructs a MultiLoop with a specific queue type. More...
 
 ~MultiLoop () override
 Defaulted destructor. More...
 
bool is_in_same_thread () const override
 Reports whether the calling thread belongs to this loop. More...
 
bool wait_for_idle (int ms=Timer::kInfinite, bool check=true) override
 Waits until both the dispatcher queue and the worker pool reach idle. More...
 

Protected Member Functions

void on_begin () override
 Hook invoked once on the dispatcher when the loop starts; constructs the worker pool. More...
 
void on_end () override
 Hook invoked once on the dispatcher when the loop exits; shuts the worker pool down. More...
 
void on_task_changed (Callback &&callback, uint32_t start_time) override
 Forwards a task to the internal pool, falling back to the inline base implementation when the pool rejects the post. More...
 

Additional Inherited Members

 Internal queue implementation type. More...
 Back-pressure strategy applied when the bounded queue is at capacity. More...
 Built-in priority levels for kPriorityType loops; higher values dispatch first. More...

Detailed Description

MessageLoop subclass that forwards every task to an internal ThreadPool.

Inherits every posting API from MessageLoop. The dispatcher pulls tasks from the queue in FIFO order; the worker pool runs them concurrently so execution order is not guaranteed even though enqueue order is.

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_numWorker count. Default: 4. A zero-worker pool rejects forwarded posts, so tasks fall back to inline execution on the dispatcher.

◆ MultiLoop() [2/2]

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

Constructs a MultiLoop with a specific queue type.

Parameters
thread_numWorker count.
typeQueue implementation type from MessageLoop::Type.

◆ ~MultiLoop()

vlink::MultiLoop::~MultiLoop ( )
override

Defaulted destructor.

Warning
Call quit and wait_for_quit before destruction; the base MessageLoop destructor runs after MultiLoop's members are already torn down and cannot guarantee the worker pool is reset.

Member Function Documentation

◆ is_in_same_thread()

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

Reports whether the calling thread belongs to this loop.

Returns
true on the dispatcher or any worker thread of the internal pool.

Reimplemented from vlink::MessageLoop.

◆ on_begin()

void vlink::MultiLoop::on_begin ( )
overrideprotectedvirtual

Hook invoked once on the dispatcher when the loop starts; constructs the worker pool.

Reimplemented from vlink::MessageLoop.

◆ on_end()

void vlink::MultiLoop::on_end ( )
overrideprotectedvirtual

Hook invoked once on the dispatcher when the loop exits; shuts the worker pool down.

Reimplemented from vlink::MessageLoop.

◆ on_task_changed()

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

Forwards a task to the internal pool, falling back to the inline base implementation when the pool rejects the post.

Parameters
callbackTask to dispatch.
start_timeMillisecond steady_clock timestamp captured at enqueue time.

Reimplemented from vlink::MessageLoop.

◆ wait_for_idle()

bool vlink::MultiLoop::wait_for_idle ( int  ms = Timer::kInfinite,
bool  check = true 
)
overridevirtual

Waits until both the dispatcher queue and the worker pool reach idle.

Parameters
msMaximum wait in milliseconds; Timer::kInfinite means no limit.
checkWhen true, rejects calls from threads owned by this loop.
Returns
true when both queues drained before the timeout.

Reimplemented from vlink::MessageLoop.


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